feat(mcp): emit server-level instructions in initialize response (#143)
Adds a universal tool-selection playbook surfaced by MCP clients (Claude Code, Cursor, opencode, LangChain, OpenAI Agent SDK) in the agent's system prompt automatically. Without this, agents have to infer tool composition from individual tool descriptions and tend to walk callers manually instead of reaching for codegraph_impact, etc. Scoped tight: only the 9 tools that exist on main today (search/context/callers/callees/impact/node/explore/files/status), no "(when present)" references to unmerged tools, no per-language guidance. ~40 lines of useful guidance. Salvaged from #121, which bundled the instructions with #117's MCP tool-registry refactor and referenced many tools that don't exist on main. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a460b856c2
commit
804ab671d4
+6
-1
@@ -19,6 +19,7 @@ import * as path from 'path';
|
||||
import CodeGraph, { findNearestCodeGraphRoot } from '../index';
|
||||
import { StdioTransport, JsonRpcRequest, JsonRpcNotification, ErrorCodes } from './transport';
|
||||
import { tools, ToolHandler } from './tools';
|
||||
import { SERVER_INSTRUCTIONS } from './server-instructions';
|
||||
|
||||
/**
|
||||
* Convert a file:// URI to a filesystem path.
|
||||
@@ -268,13 +269,17 @@ export class MCPServer {
|
||||
// Try to initialize the default project (non-fatal if it fails)
|
||||
await this.tryInitializeDefault(projectPath);
|
||||
|
||||
// We accept the client's protocol version but respond with our supported version
|
||||
// We accept the client's protocol version but respond with our supported version.
|
||||
// The `instructions` field is surfaced by MCP clients in the agent's system
|
||||
// prompt automatically — it's the right place for the universal tool-selection
|
||||
// playbook, ahead of individual tool descriptions.
|
||||
this.transport.sendResult(request.id, {
|
||||
protocolVersion: PROTOCOL_VERSION,
|
||||
capabilities: {
|
||||
tools: {},
|
||||
},
|
||||
serverInfo: SERVER_INFO,
|
||||
instructions: SERVER_INSTRUCTIONS,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user