-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Summary
The FastMcpStarter currently does not expose the instructions parameter, which is a standard field in the MCP (Model Context Protocol) specification. This prevents servers from providing usage instructions to clients, limiting the LLM's ability to understand available tools and resources.
Background
According to the MCP specification, instructions is an optional field in the InitializeResult that describes how to use the server and its features. This information can be used by clients to improve the LLM's understanding of available tools, resources, etc., and is typically added to the system prompt.
From the MCP SDK types:
/**
* Instructions describing how to use the server and its features.
*
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc.
* It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
*/
instructions: z.ZodOptional<z.ZodString>;Current Issue
In FastMcpStarter.ts, the FastMCP server is created without the instructions parameter:
const server = new FastMCP({
name: opts.serviceId || 'nuwa-mcp-server',
version: '1.0.0',
// Missing: instructions parameter
});Similarly, FastMCPSession is created without instructions:
const session = new FastMCPSession({
name: opts.serviceId || 'nuwa-mcp-server',
version: '1.0.0',
// Missing: instructions parameter
// ... other config
});How Clients Access Instructions
MCP clients access instructions through the standard initialization handshake:
- Client calls
connect()method (returnsPromise<void>) - After successful connection, client calls
getInstructions()to retrieve server instructions - Instructions are automatically included in the
InitializeResultduring the MCP handshake
// Client usage example
const client = new McpClient({ name: 'my-client', version: '1.0.0' });
await client.connect(transport);
const instructions = client.getInstructions(); // Gets instructions from serverProposed Solution
1. Add instructions option to FastMcpServerOptions
export interface FastMcpServerOptions extends McpPaymentKitOptions {
/** Instructions describing how to use the server and its features */
instructions?: string;
port?: number;
endpoint?: `/${string}`;
register?: (registrar: PaymentMcpToolRegistrar) => void;
wellKnown?: {
enabled?: boolean;
path?: `/${string}`;
};
}2. Pass instructions to FastMCP constructor
const server = new FastMCP({
name: opts.serviceId || 'nuwa-mcp-server',
version: '1.0.0',
instructions: opts.instructions, // Add this line
});3. Pass instructions to FastMCPSession constructor
const session = new FastMCPSession({
name: opts.serviceId || 'nuwa-mcp-server',
version: '1.0.0',
instructions: opts.instructions, // Add this line
// ... other config
});4. Update helper functions
Both createFastMcpServer and createFastMcpServerFromEnv should accept and forward the instructions parameter.
Example Usage
After implementation, developers could use it like this:
const server = await createFastMcpServerFromEnv(env, {
serviceId: "my-service",
instructions: "This server provides weather data and location services. Use get_weather for current conditions and search_locations to find places.",
port: 8080,
// ... other options
});Benefits
- Improved LLM Understanding: Instructions help LLMs better understand how to use the server's tools and resources
- Better User Experience: More context leads to more accurate tool usage and better results
- MCP Compliance: Follows the standard MCP specification for server metadata
- Backward Compatibility: Adding optional instructions parameter doesn't break existing code
Files to Modify
nuwa-kit/typescript/packages/payment-kit/src/transport/mcp/FastMcpStarter.ts- Add
instructions?toFastMcpServerOptionsinterface - Pass instructions to FastMCP constructor
- Pass instructions to FastMCPSession constructor
- Update function signatures as needed
- Add
Acceptance Criteria
-
FastMcpServerOptionsinterface includes optionalinstructionsparameter - Instructions are passed to both
FastMCPandFastMCPSessionconstructors -
createFastMcpServerandcreateFastMcpServerFromEnvaccept instructions parameter - Existing functionality remains unchanged (backward compatible)
- MCP clients can retrieve instructions via
getInstructions()method - Documentation/examples updated to show instructions usage
Priority
Medium - This is a standard MCP feature that improves the developer experience and LLM interaction quality, but doesn't break existing functionality.