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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamcp/mcp-server-metamcp",
"version": "0.4.4",
"version": "0.4.5",
"description": "MCP Server MetaMCP manages all your other MCPs in one MCP.",
"scripts": {
"build": "tsc && shx chmod +x dist/*.js",
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createMetaMcpClient = (
const client = new Client(
{
name: "MetaMCP",
version: "0.4.4",
version: "0.4.5",
},
{
capabilities: {
Expand Down
1 change: 1 addition & 0 deletions src/fetch-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getMetaMcpApiBaseUrl, getMetaMcpApiKey } from "./utils.js";

export enum ProfileCapability {
TOOLS_MANAGEMENT = "TOOLS_MANAGEMENT",
TOOL_LOGS = "TOOL_LOGS",
}

let _capabilitiesCache: ProfileCapability[] | null = null;
Expand Down
73 changes: 64 additions & 9 deletions src/mcp-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import {
getProfileCapabilities,
ProfileCapability,
} from "./fetch-capabilities.js";
import { ToolLogManager } from "./tool-logs.js";

const toolToClient: Record<string, ConnectedClient> = {};
const toolToServerUuid: Record<string, string> = {};
const promptToClient: Record<string, ConnectedClient> = {};
const resourceToClient: Record<string, ConnectedClient> = {};
const inactiveToolsMap: Record<string, boolean> = {};
Expand All @@ -38,7 +40,7 @@ export const createServer = async () => {
const server = new Server(
{
name: "MetaMCP",
version: "0.4.4",
version: "0.4.5",
},
{
capabilities: {
Expand Down Expand Up @@ -104,6 +106,7 @@ export const createServer = async () => {
.map((tool) => {
const toolName = `${sanitizeName(serverName)}__${tool.name}`;
toolToClient[toolName] = session;
toolToServerUuid[toolName] = uuid;
return {
...tool,
name: toolName,
Expand Down Expand Up @@ -149,31 +152,59 @@ export const createServer = async () => {
// Call Tool Handler
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;

const originalToolName = name.split("__")[1];
const clientForTool = toolToClient[name];
const toolLogManager = ToolLogManager.getInstance();
let logId: string | undefined;
let startTime = Date.now();

if (!clientForTool) {
throw new Error(`Unknown tool: ${name}`);
}

// Only check inactive tools if tools management capability is present
// Get MCP server UUID for the tool
const mcpServerUuid = toolToServerUuid[name] || "";

if (!mcpServerUuid) {
console.error(`Could not determine MCP server UUID for tool: ${name}`);
}

// Get profile capabilities
const profileCapabilities = await getProfileCapabilities();

// Only check inactive tools if tools management capability is present
if (
profileCapabilities.includes(ProfileCapability.TOOLS_MANAGEMENT) &&
inactiveToolsMap[name]
) {
throw new Error(`Tool is inactive: ${name}`);
}

// Check if TOOL_LOGS capability is enabled
const hasToolsLogCapability = profileCapabilities.includes(
ProfileCapability.TOOL_LOGS
);

try {
const toolName = name.split("__")[1];
// Create initial pending log only if TOOL_LOGS capability is present
if (hasToolsLogCapability) {
const log = await toolLogManager.createLog(
originalToolName,
mcpServerUuid,
args || {}
);
logId = log.id;
}

// Reset the timer right before making the actual tool call
startTime = Date.now();

// Use the correct schema for tool calls
return await clientForTool.client.request(
const result = await clientForTool.client.request(
{
method: "tools/call",
params: {
name: toolName,
name: originalToolName,
arguments: args || {},
_meta: {
progressToken: request.params._meta?.progressToken,
Expand All @@ -182,10 +213,34 @@ export const createServer = async () => {
},
CompatibilityCallToolResultSchema
);
} catch (error) {

const executionTime = Date.now() - startTime;

// Update log with success result only if TOOL_LOGS capability is present
if (hasToolsLogCapability && logId) {
try {
await toolLogManager.completeLog(logId, result, executionTime);
} catch (logError) {}
}

return result;
} catch (error: any) {
const executionTime = Date.now() - startTime;

// Update log with error only if TOOL_LOGS capability is present
if (hasToolsLogCapability && logId) {
try {
await toolLogManager.failLog(
logId,
error.message || "Unknown error",
executionTime
);
} catch (logError) {}
}

console.error(
`Error calling tool through ${
clientForTool.client.getServerVersion()?.name
`Error calling tool "${name}" through ${
clientForTool.client.getServerVersion()?.name || "unknown"
}:`,
error
);
Expand Down
Loading