Skip to content

MCP: Deal with the server.server echo? #425

@kentcdodds

Description

@kentcdodds

When we need to access the underlying server implementation this is what we have to do:

import { McpAgent } from "agents/mcp";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

export class MyMCP extends McpAgent {
	server = new McpServer({/* ... */});

	async init() {
		// server.server echo is annoying and confusing
		this.server.server.setRequestHandler(
			SetLevelRequestSchema,
			async (request, extra) => {
				// ... handler logic
			},
		);
	}
}

It's kind of annoying (and it's the MCP SKD's fault). I would rather it be this.mcp.server.setRequestHandler:

import { McpAgent } from "agents/mcp";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

export class MyMCP extends McpAgent {
	mcp = new McpServer({/* ... */});

	async init() {
		this.mcp.server.setRequestHandler(
			SetLevelRequestSchema,
			async (request, extra) => {
				// ... handler logic
			},
		);
	}
}

However, McpAgent requires the server to be set to the server property.

This is just a small quality of life thing, but I think it should be easy enough to un-document the server name, document the mcp name, and support both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions