Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions server/routes/mcp/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const servers = new Hono();

// List all connected servers with their status
servers.get("/", async (c) => {
// TODO: Figure out how to incorporate MCPClientManager
try {
const mcpJamClientManager = c.mcpJamClientManager;

// Get all server configurations and statuses
const connectedServers = mcpJamClientManager.getConnectedServers();

const serverList = Object.entries(connectedServers).map(
([serverId, serverInfo]) => ({
id: serverId,
Expand Down Expand Up @@ -41,7 +40,6 @@ servers.get("/status/:serverId", async (c) => {
try {
const serverId = c.req.param("serverId");
const mcpJamClientManager = c.mcpJamClientManager;

const status = mcpJamClientManager.getConnectionStatus(serverId);

return c.json({
Expand All @@ -65,8 +63,9 @@ servers.get("/status/:serverId", async (c) => {
servers.delete("/:serverId", async (c) => {
try {
const serverId = c.req.param("serverId");
const mcpJamClientManager = c.mcpJamClientManager;

const mcpJamClientManager = c.mcpJamClientManager; // TODO: Remove MCPJamClientManager
const mcpClientManager = c.mcpClientManager;
await mcpClientManager.disconnectServer(serverId);
await mcpJamClientManager.disconnectFromServer(serverId);

return c.json({
Expand Down Expand Up @@ -100,7 +99,11 @@ servers.post("/reconnect", async (c) => {
);
}

const mcpJamClientManager = c.mcpJamClientManager;
const mcpJamClientManager = c.mcpJamClientManager; // TODO: Remove MCPJamClientManager
const mcpClientManager = c.mcpClientManager;

await mcpClientManager.disconnectServer(serverId);
await mcpClientManager.connectToServer(serverId, serverConfig);

// Disconnect first, then reconnect
await mcpJamClientManager.disconnectFromServer(serverId);
Expand Down
11 changes: 11 additions & 0 deletions shared/mcp-client-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ export class MCPClientManager {
return metadataMap ? Object.fromEntries(metadataMap) : {};
}

pingServer(serverId: string, options?: RequestOptions) {
const client = this.getClientById(serverId);
try {
client.ping(options);
} catch (error) {
throw new Error(
`Failed to ping MCP server "${serverId}": ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
}

async executeTool(
serverId: string,
toolName: string,
Expand Down