Skip to content

Commit b89aa68

Browse files
committed
Expose getMcpServerState method
1 parent 54e1986 commit b89aa68

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.changeset/gold-zoos-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
Expose getMcpServerState internally in agent

packages/agents/src/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
Tool,
2222
Resource,
2323
Prompt,
24+
ServerCapabilities,
2425
} from "@modelcontextprotocol/sdk/types.js";
2526

2627
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
@@ -195,6 +196,8 @@ export type MCPServer = {
195196
server_url: string;
196197
auth_url: string | null;
197198
state: "authenticating" | "connecting" | "ready" | "discovering" | "failed";
199+
instructions: string | null;
200+
capabilities: ServerCapabilities | null;
198201
};
199202

200203
/**
@@ -396,7 +399,7 @@ export class Agent<Env, State = unknown> extends Server<Env> {
396399
this.broadcast(
397400
JSON.stringify({
398401
type: "cf_agent_mcp_servers",
399-
mcp: this._getMcpServerStateInternal(),
402+
mcp: this.getMcpServerState(),
400403
})
401404
);
402405

@@ -508,7 +511,7 @@ export class Agent<Env, State = unknown> extends Server<Env> {
508511
connection.send(
509512
JSON.stringify({
510513
type: "cf_agent_mcp_servers",
511-
mcp: this._getMcpServerStateInternal(),
514+
mcp: this.getMcpServerState(),
512515
})
513516
);
514517

@@ -548,7 +551,7 @@ export class Agent<Env, State = unknown> extends Server<Env> {
548551
this.broadcast(
549552
JSON.stringify({
550553
type: "cf_agent_mcp_servers",
551-
mcp: this._getMcpServerStateInternal(),
554+
mcp: this.getMcpServerState(),
552555
})
553556
);
554557

@@ -952,7 +955,7 @@ export class Agent<Env, State = unknown> extends Server<Env> {
952955
this.broadcast(
953956
JSON.stringify({
954957
type: "cf_agent_mcp_servers",
955-
mcp: this._getMcpServerStateInternal(),
958+
mcp: this.getMcpServerState(),
956959
})
957960
);
958961

@@ -1049,12 +1052,12 @@ export class Agent<Env, State = unknown> extends Server<Env> {
10491052
this.broadcast(
10501053
JSON.stringify({
10511054
type: "cf_agent_mcp_servers",
1052-
mcp: this._getMcpServerStateInternal(),
1055+
mcp: this.getMcpServerState(),
10531056
})
10541057
);
10551058
}
10561059

1057-
private _getMcpServerStateInternal(): MCPServersState {
1060+
getMcpServerState(): MCPServersState {
10581061
const mcpState: MCPServersState = {
10591062
servers: {},
10601063
tools: this.mcp.listTools(),
@@ -1072,6 +1075,9 @@ export class Agent<Env, State = unknown> extends Server<Env> {
10721075
server_url: server.server_url,
10731076
auth_url: server.auth_url,
10741077
state: this.mcp.mcpConnections[server.id].connectionState,
1078+
instructions: this.mcp.mcpConnections[server.id].instructions ?? null,
1079+
capabilities:
1080+
this.mcp.mcpConnections[server.id].serverCapabilities ?? null,
10751081
};
10761082
}
10771083

0 commit comments

Comments
 (0)