Skip to content

Conversation

kentcdodds
Copy link

Technically there are some breaking changes here, but they're either done in a non-breaking way or they're breaking features I do not think are used (and are not documented).

Closes #425

  • BREAKING: Renamed server property to mcp in McpAgent and updated related examples.
  • BREAKING: Renamed mcp property to mcpClientManager in Agent class to avoid naming conflicts.
  • Added backward compatibility for server property in McpAgent with a deprecation warning.
  • Updated all MCP examples to reflect the new naming convention.
  • Improved property naming consistency across the MCP implementation.

…ed developer experience

- **BREAKING**: Renamed `server` property to `mcp` in `McpAgent` and updated related examples.
- **BREAKING**: Renamed `mcp` property to `mcpClientManager` in `Agent` class to avoid naming conflicts.
- Added backward compatibility for `server` property in `McpAgent` with a deprecation warning.
- Updated all MCP examples to reflect the new naming convention.
- Improved property naming consistency across the MCP implementation.
Copy link

changeset-bot bot commented Aug 28, 2025

🦋 Changeset detected

Latest commit: c8994e2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines -294 to +297
mcp: MCPClientManager = new MCPClientManager(this._ParentClass.name, "0.0.1");
mcpClientManager: MCPClientManager = new MCPClientManager(
this._ParentClass.name,
"0.0.1"
);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, I do not think this change is necessary and I'm happy to back it out. This is the most breaking thing about this PR. Though again I don't think anyone is intended to use this property (it's also undocumented).

Comment on lines +213 to +215
get mcpClientManager() {
return this._agent.mcpClientManager;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is technically breaking for anyone who's using the client manager, but I don't think anyone is and it's not documented.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very happy with this change. I think this is super confusing at the moment.

We should keep the mcp() and mark it as deprecated to be removed in the next version.

Comment on lines +369 to +379
* @deprecated Use the `mcp` property instead for better developer experience.
*/
server?: MaybePromise<McpServer | Server>;
/**
* This is only set as optional for backward compatibility in case you're
* using the legacy `server` property. It's recommended to use `mcp`.
*
* In the future, we'll make this a required abstract property to implement
* and remove the `server` property.
*/
abstract server: MaybePromise<McpServer | Server>;
mcp?: MaybePromise<McpServer | Server>;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the primary focus of this PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be open to this changing to mcpServer() ?


export class MyMCP extends McpAgent<Env, State, {}> {
server = new McpServer({
mcp = new McpServer({
Copy link

@cliffhall cliffhall Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mcp could be a getter that returns server? That way it would be totally backward compatible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that would allow me to do this:

export class MyMCP extends McpAgent {
	mcp = new McpServer({}); // <-- this is the desired API

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

export class MyMCP extends McpAgent {

	get mcp(): McpServer {
		return this.server;
	}
        
	server = new McpServer({});

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do that myself without having to change anything in agents. That's actually a reasonable workaround if they decide this is more trouble than it's worth. Thanks for the idea!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually I can't do that because mcp is already set to the mcpClientManager 🙁

Copy link

pkg-pr-new bot commented Aug 29, 2025

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@427

commit: c8994e2

@@ -0,0 +1,31 @@
---
"@cloudflare/agents": major
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to major because there was an example of using the previous existing mcp property so people may actually be using that.

};

const result = await this.mcp.callTool({
const result = await this.mcpClientManager.callTool({
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the breaking change.

@whoiskatrin
Copy link
Collaborator

whoiskatrin commented Sep 12, 2025

FYI I'm not against this, I think the change makes life better. My concern it's a breaking change, if we do so, I'd like to make a bigger release and then also prepare people for this migration.

@kentcdodds
Copy link
Author

I'm fine waiting 👍

@whoiskatrin whoiskatrin added on the roadmap Feature accepted and planned for implementation mcp Issues related to MCP functionality breaking change labels Sep 15, 2025
Comment on lines +222 to +230
get mcpServer(): MaybePromise<McpServer | Server> {
const server = this.mcp ?? this.server;
if (!server) {
throw new Error(
'Neither the `mcp` nor `server` property is set. Please set "mcp".'
);
}

return server;
Copy link
Collaborator

@mattzcarey mattzcarey Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this adds to the confusion right now.

IMO mcpServer should be the new name for server(). Thereby we can have a deprecation notice on the mcp() naming and keep everything clean. Much happier for more descriptive names especially as this class gets bigger.

Copy link
Collaborator

@mattzcarey mattzcarey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed server.server is super annoying and doesnt give you any info on what each class should do. Also agreed that the clientManager being called mcp is confusing.

To make migration a bit smoother I would propose:

  1. mcp -> mcpClientManager
  2. server -> mcpServer

the 2. also emulates the Anthropic way of doing things in MCP TS SDK where the McpServer is a higher level abstraction and the Server is the lower level one. This will be easy to land as we can deprecate the old names with no conflict.

@threepointone
Copy link
Collaborator

but that still means writing mcpServer.server

@mattzcarey
Copy link
Collaborator

mattzcarey commented Oct 9, 2025

but that still means writing mcpServer.server

i hate that much less. You also only need to write that when accessing the underlying sdk server which makes sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change mcp Issues related to MCP functionality on the roadmap Feature accepted and planned for implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: Deal with the server.server echo?

6 participants