mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-01 04:34:23 +01:00
feat: add mcp tab
This commit is contained in:
@@ -11,6 +11,7 @@ import type { SerializableAliveTask } from "../service/claude-code/types";
|
||||
import { getEventBus } from "../service/events/EventBus";
|
||||
import { getFileWatcher } from "../service/events/fileWatcher";
|
||||
import { sseEventResponse } from "../service/events/sseEventResponse";
|
||||
import { getMcpList } from "../service/mcp/getMcpList";
|
||||
import { getProject } from "../service/project/getProject";
|
||||
import { getProjects } from "../service/project/getProjects";
|
||||
import { getSession } from "../service/session/getSession";
|
||||
@@ -169,6 +170,11 @@ export const routes = (app: HonoAppType) => {
|
||||
});
|
||||
})
|
||||
|
||||
.get("/mcp/list", async (c) => {
|
||||
const { servers } = await getMcpList();
|
||||
return c.json({ servers });
|
||||
})
|
||||
|
||||
.post(
|
||||
"/projects/:projectId/new-session",
|
||||
zValidator(
|
||||
|
||||
45
src/server/service/mcp/getMcpList.ts
Normal file
45
src/server/service/mcp/getMcpList.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { execSync } from "node:child_process";
|
||||
|
||||
export interface McpServer {
|
||||
name: string;
|
||||
command: string;
|
||||
}
|
||||
|
||||
export const getMcpList = async (): Promise<{ servers: McpServer[] }> => {
|
||||
try {
|
||||
const output = execSync("claude mcp list", {
|
||||
encoding: "utf8",
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
const servers: McpServer[] = [];
|
||||
const lines = output.trim().split("\n");
|
||||
|
||||
for (const line of lines) {
|
||||
// Skip header lines and status indicators
|
||||
if (line.includes("Checking MCP server health") || line.trim() === "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse lines like "context7: npx -y @upstash/context7-mcp@latest - ✓ Connected"
|
||||
const colonIndex = line.indexOf(":");
|
||||
if (colonIndex > 0) {
|
||||
const name = line.substring(0, colonIndex).trim();
|
||||
const rest = line.substring(colonIndex + 1).trim();
|
||||
|
||||
// Remove status indicators (✓ Connected, ✗ Failed, etc.)
|
||||
const command = rest.replace(/\s*-\s*[✓✗].*$/, "").trim();
|
||||
|
||||
if (name && command) {
|
||||
servers.push({ name, command });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { servers };
|
||||
} catch (error) {
|
||||
console.error("Failed to get MCP list:", error);
|
||||
// Return empty list if command fails
|
||||
return { servers: [] };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user