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
11 changes: 7 additions & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ export default tseslint.config(
'import-x/no-amd': 'error',
'import-x/no-import-module-exports': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unused-vars': 'off',

// General rules
'no-console': 'error',
'prefer-const': 'error',

// Ban dynamic imports - only top-level import declarations allowed
'no-restricted-syntax': [
'error',
{
selector: 'ImportExpression',
message: 'Dynamic imports are not allowed. Use top-level import declarations only.'
}
message:
'Dynamic imports are not allowed. Use top-level import declarations only.',
},
],
},
},
Expand All @@ -47,4 +49,5 @@ export default tseslint.config(
'no-console': 'off',
},
}
);
);

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mcp-controller",
"version": "0.1.0",
"version": "0.1.1",
"description": "MCP server proxy that forwards JSON RPC communication between MCP clients and target servers",
"type": "module",
"bin": {
Expand Down
7 changes: 5 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { McpProxyServer } from './proxy-server.js';
import type { ProxyConfig, Tool } from './types.js';
import { TargetServerManager } from './target-server.js';
import { matchesToolPattern } from './utils.js';

function parseListToolsArguments(args: string[]): ProxyConfig {
if (args.length === 0) {
Expand Down Expand Up @@ -65,7 +66,9 @@ function parseArguments(): ProxyConfig {
if (args.length === 0) {
process.stderr.write('Usage: mcp-controller [--enabled-tools <tool1,tool2,...>] [--disabled-tools <tool1,tool2,...>] <command> [args...]\n');
process.stderr.write(' mcp-controller list-tools [--enabled-tools <tool1,tool2,...>] [--disabled-tools <tool1,tool2,...>] <command> [args...]\n');
process.stderr.write('Tool patterns support wildcards: use * to match any characters (e.g., get_* matches get_logs, get_metrics)\n');
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The indentation is inconsistent with the surrounding lines. This line should be indented to match the other process.stderr.write statements above and below it.

Copilot uses AI. Check for mistakes.

process.stderr.write('Example: mcp-controller --enabled-tools add,subtract bun run server.ts\n');
process.stderr.write('Example: mcp-controller --enabled-tools "get_*,list_*" bun run server.ts\n');
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The indentation is inconsistent with the surrounding lines. This line should be indented to match the other process.stderr.write statements above and below it.

Suggested change
process.stderr.write('Example: mcp-controller --enabled-tools "get_*,list_*" bun run server.ts\n');
process.stderr.write('Example: mcp-controller --enabled-tools "get_*,list_*" bun run server.ts\n');

Copilot uses AI. Check for mistakes.

process.stderr.write('Example: mcp-controller list-tools bun run server.ts\n');
process.stderr.write('Example: mcp-controller --disabled-tools dangerous-tool bun run server.ts\n');
process.exit(1);
Expand Down Expand Up @@ -201,9 +204,9 @@ async function listTools(config: ProxyConfig): Promise<void> {
let tools = response.result.tools || [];

if (config.enabledTools) {
tools = tools.filter((tool: Tool) => config.enabledTools!.includes(tool.name));
tools = tools.filter((tool: Tool) => config.enabledTools!.some(pattern => matchesToolPattern(tool.name, pattern)));
} else if (config.disabledTools) {
tools = tools.filter((tool: Tool) => !config.disabledTools!.includes(tool.name));
tools = tools.filter((tool: Tool) => !config.disabledTools!.some(pattern => matchesToolPattern(tool.name, pattern)));
}

// Print tools in the requested format
Expand Down
5 changes: 3 additions & 2 deletions src/proxy-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ProxyConfig, TargetServerProcess, JsonRpcMessage, ToolsListResult } from './types.js';
import { TargetServerManager } from './target-server.js';
import { matchesToolPattern } from './utils.js';

export class McpProxyServer {
private targetManager: TargetServerManager;
Expand Down Expand Up @@ -107,9 +108,9 @@ export class McpProxyServer {
let filteredTools = result.tools;

if (enabledTools) {
filteredTools = filteredTools.filter(tool => enabledTools.includes(tool.name));
filteredTools = filteredTools.filter(tool => enabledTools.some(pattern => matchesToolPattern(tool.name, pattern)));
} else if (disabledTools) {
filteredTools = filteredTools.filter(tool => !disabledTools.includes(tool.name));
filteredTools = filteredTools.filter(tool => !disabledTools.some(pattern => matchesToolPattern(tool.name, pattern)));
}

return {
Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function matchesToolPattern(toolName: string, pattern: string): boolean {
// Exact match for patterns without wildcards (backward compatibility)
if (!pattern.includes('*')) {
return toolName === pattern;
}

// Convert glob pattern to regex with proper escaping
const escapedPattern = pattern
.replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape regex special chars
.replace(/\*/g, '.*'); // Replace * with .*

const regex = new RegExp(`^${escapedPattern}$`);
return regex.test(toolName);
}
13 changes: 13 additions & 0 deletions tests/fixtures/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ server.registerTool(
})
);

// Add a subtraction tool
server.registerTool(
'subtract',
{
title: 'Subtraction Tool',
description: 'Subtract two numbers',
inputSchema: { a: z.number(), b: z.number() },
},
async ({ a, b }) => ({
content: [{ type: 'text', text: String(a - b) }],
})
);

// Add a tool that returns the initialization arguments
server.registerTool(
'get-args',
Expand Down
Loading