mcp-filter 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.5.0] - 2025-11-22
9
+
10
+ ### Added
11
+ - **Multi-Transport Support**: Filter both local and remote MCP servers
12
+ - HTTP transport for remote MCP servers (Streamable HTTP)
13
+ - SSE transport for legacy servers (deprecated, backward compatibility)
14
+ - Stdio transport for local servers (existing functionality, unchanged)
15
+ - `--upstream-url <url>` flag to connect to remote HTTP/SSE servers
16
+ - `--transport <type>` flag to explicitly specify transport type (stdio/http/sse)
17
+ - `--header <header>` flag to add custom HTTP headers (e.g., authentication)
18
+ - `--help` flag to show usage information
19
+ - Transport factory pattern for clean separation of transport logic
20
+ - HTTP transport integration tests with context7 public endpoint
21
+ - Comprehensive CLI tests for new transport options
22
+
23
+ ### Changed
24
+ - **Breaking**: `FilterConfig` now uses `transportConfig` instead of `upstreamCommand`
25
+ - Upgraded `@modelcontextprotocol/sdk` from 1.0.4 to 1.22.0
26
+ - Updated peerDependencies to require SDK >=1.10.0 (for HTTP transport)
27
+ - CLI now auto-detects transport type (HTTP for URLs, stdio for commands)
28
+ - Updated documentation with HTTP/SSE usage examples
29
+ - Reorganized codebase with new `src/types.ts` and `src/transport.ts` modules
30
+
31
+ ### Fixed
32
+ - Increased timeout for integration tests using `npx` to prevent flaky failures
33
+ - Updated architecture validation tests for new transport factory pattern
34
+
35
+ ## [0.4.0] - 2025-10-08
36
+
37
+ ### Fixed
38
+ - Fixed connection failures caused by double-spawning upstream MCP server subprocess
39
+ - Fixed "command not found" errors with `npx` by properly passing environment variables
40
+ - Fixed stderr forwarding from upstream servers
41
+
42
+ ### Changed
43
+ - Delegated subprocess management entirely to `StdioClientTransport` (breaking change in internal architecture)
44
+ - Improved error forwarding by using `stderr: "inherit"` instead of `"pipe"`
45
+
46
+ ### Added
47
+ - Comprehensive integration tests for subprocess management and real-world MCP server compatibility
48
+ - Architecture validation tests to prevent regression of subprocess spawning anti-patterns
49
+ - Debugging guide for common MCP communication issues in CLAUDE.md
50
+ - ADR-003 documenting subprocess delegation pattern
51
+ - Claude Code configuration with custom slash commands
52
+
53
+ ## [0.3.0] - 2025-01-XX
54
+
55
+ ### Added
56
+ - Rsync-style pattern evaluation (first match wins)
57
+ - Support for both `--include` and `--exclude` patterns
58
+
59
+ ### Changed
60
+ - Pattern matching now evaluates in order with first-match-wins semantics
61
+
62
+ ## [0.2.0] - 2025-01-XX
63
+
64
+ ### Added
65
+ - Comprehensive documentation updates
66
+ - Testing infrastructure with Vitest
67
+
68
+ ## [0.1.0] - 2025-01-XX
69
+
70
+ ### Added
71
+ - Initial release
72
+ - Basic MCP proxy server with pattern-based filtering
73
+ - Support for filtering tools, resources, and prompts
74
+ - Glob pattern matching using minimatch
package/README.md CHANGED
@@ -15,7 +15,7 @@ npx mcp-filter [options] -- <upstream-command>
15
15
 
16
16
  ## Usage
17
17
 
18
- ### Basic Usage
18
+ ### Local MCP Servers (Stdio Transport)
19
19
 
20
20
  ```bash
21
21
  # Exclude mode: filter out specific tools
@@ -30,17 +30,49 @@ npx mcp-filter --exclude "browser_close" --include "browser_*" -- npx @playwrigh
30
30
  # Multiple patterns
31
31
  npx mcp-filter --exclude "playwright*" --exclude "unsafe_*" -- npx @playwright/mcp
32
32
 
33
- # Use with any MCP server
33
+ # Use with any local MCP server
34
34
  npx mcp-filter --exclude "debug*" -- node my-mcp-server.js
35
35
  ```
36
36
 
37
+ ### Remote MCP Servers (HTTP/SSE Transport)
38
+
39
+ ```bash
40
+ # Filter remote HTTP server (e.g., Notion, Stripe, Linear)
41
+ npx mcp-filter --exclude "delete_*" --upstream-url https://mcp.notion.com/mcp
42
+
43
+ # Filter with custom headers (authentication, etc.)
44
+ npx mcp-filter --exclude "admin_*" \
45
+ --upstream-url https://api.example.com/mcp \
46
+ --header "Authorization: Bearer your-token-here"
47
+
48
+ # SSE transport (deprecated, for legacy servers)
49
+ npx mcp-filter --transport sse \
50
+ --upstream-url https://mcp.asana.com/sse \
51
+ --exclude "dangerous_*"
52
+
53
+ # Complex filtering with remote servers
54
+ npx mcp-filter \
55
+ --exclude "delete_*" \
56
+ --exclude "update_*" \
57
+ --include "read_*" \
58
+ --upstream-url https://mcp.example.com/mcp
59
+ ```
60
+
37
61
  ## Options
38
62
 
63
+ ### Filtering Options
39
64
  - `--exclude <pattern>` - Exclude tools/resources/prompts matching this pattern
40
65
  - `--include <pattern>` - Include ONLY tools/resources/prompts matching this pattern (whitelist mode)
41
- - `--` - Separates filter options from upstream server command
42
66
 
43
- Both options can be specified multiple times and combined together.
67
+ ### Transport Options
68
+ - `--upstream-url <url>` - Connect to remote HTTP/SSE server (instead of local command)
69
+ - `--transport <type>` - Transport type: `stdio`, `http`, `sse` (auto-detected if omitted)
70
+ - `--header <header>` - Add HTTP header (format: `"Key: Value"`, HTTP/SSE only, can be repeated)
71
+ - `--` - Separates options from local server command (stdio mode only)
72
+
73
+ **Note**: `--upstream-url` and `--` are mutually exclusive. Use `--upstream-url` for remote servers, or `-- <command>` for local servers.
74
+
75
+ All options can be specified multiple times and combined together.
44
76
 
45
77
  **Filtering style:** rsync-style evaluation where patterns are evaluated in the order specified, and first match wins.
46
78
 
package/dist/cli.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- export interface FilterPattern {
2
- type: "include" | "exclude";
3
- pattern: string;
4
- }
5
- export interface FilterConfig {
6
- patterns: FilterPattern[];
7
- upstreamCommand: string[];
8
- }
1
+ import { FilterConfig } from "./types.js";
9
2
  export declare function parseArgs(args: string[]): FilterConfig;
10
3
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY,CAkDtD"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,YAAY,EAGb,MAAM,YAAY,CAAC;AAEpB,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY,CAkKtD"}
package/dist/cli.js CHANGED
@@ -1,6 +1,9 @@
1
1
  export function parseArgs(args) {
2
2
  const patterns = [];
3
3
  const upstreamCommand = [];
4
+ let upstreamUrl;
5
+ let explicitTransport;
6
+ const headers = {};
4
7
  let inUpstreamCommand = false;
5
8
  for (let i = 0; i < args.length; i++) {
6
9
  const arg = args[i];
@@ -28,14 +31,107 @@ export function parseArgs(args) {
28
31
  patterns.push({ type: "include", pattern });
29
32
  continue;
30
33
  }
34
+ if (arg === "--upstream-url") {
35
+ const url = args[++i];
36
+ if (!url) {
37
+ throw new Error("--upstream-url requires a URL argument");
38
+ }
39
+ upstreamUrl = url;
40
+ continue;
41
+ }
42
+ if (arg === "--transport") {
43
+ const transport = args[++i];
44
+ if (!transport) {
45
+ throw new Error("--transport requires a transport type argument");
46
+ }
47
+ if (transport !== "stdio" && transport !== "http" && transport !== "sse") {
48
+ throw new Error(`Invalid transport type: ${transport}. Must be one of: stdio, http, sse`);
49
+ }
50
+ explicitTransport = transport;
51
+ continue;
52
+ }
53
+ if (arg === "--header") {
54
+ const header = args[++i];
55
+ if (!header) {
56
+ throw new Error("--header requires a header value");
57
+ }
58
+ const colonIndex = header.indexOf(":");
59
+ if (colonIndex === -1) {
60
+ throw new Error(`Invalid header format: ${header}. Expected format: "Key: Value"`);
61
+ }
62
+ const key = header.slice(0, colonIndex).trim();
63
+ const value = header.slice(colonIndex + 1).trim();
64
+ headers[key] = value;
65
+ continue;
66
+ }
67
+ if (arg === "--help" || arg === "-h") {
68
+ throw new Error("help");
69
+ }
31
70
  throw new Error(`Unknown argument: ${arg}`);
32
71
  }
33
- if (upstreamCommand.length === 0) {
34
- throw new Error("No upstream command specified. Use -- to separate filter args from upstream command");
72
+ // Validate: cannot specify both URL and command
73
+ if (upstreamUrl && upstreamCommand.length > 0) {
74
+ throw new Error("Cannot specify both --upstream-url and command after --. Use one or the other.");
75
+ }
76
+ // Build transport config
77
+ let transportConfig;
78
+ if (upstreamUrl) {
79
+ // URL-based transport (http or sse)
80
+ let transportType;
81
+ if (explicitTransport) {
82
+ if (explicitTransport === "stdio") {
83
+ throw new Error("--transport stdio cannot be used with --upstream-url. Use command after -- instead.");
84
+ }
85
+ transportType = explicitTransport;
86
+ }
87
+ else {
88
+ // Auto-detect: default to http
89
+ transportType = "http";
90
+ }
91
+ // Validate URL format
92
+ try {
93
+ new URL(upstreamUrl);
94
+ }
95
+ catch (e) {
96
+ throw new Error(`Invalid URL: ${upstreamUrl}`);
97
+ }
98
+ if (transportType === "http") {
99
+ transportConfig = {
100
+ type: "http",
101
+ url: upstreamUrl,
102
+ headers: Object.keys(headers).length > 0 ? headers : undefined,
103
+ };
104
+ }
105
+ else {
106
+ transportConfig = {
107
+ type: "sse",
108
+ url: upstreamUrl,
109
+ headers: Object.keys(headers).length > 0 ? headers : undefined,
110
+ };
111
+ }
112
+ }
113
+ else if (upstreamCommand.length > 0) {
114
+ // Command-based transport (stdio)
115
+ if (explicitTransport && explicitTransport !== "stdio") {
116
+ throw new Error(`--transport ${explicitTransport} requires --upstream-url. Use --transport stdio or omit --transport for command-based servers.`);
117
+ }
118
+ if (Object.keys(headers).length > 0) {
119
+ throw new Error("--header can only be used with --upstream-url");
120
+ }
121
+ transportConfig = {
122
+ type: "stdio",
123
+ command: upstreamCommand,
124
+ env: process.env,
125
+ };
126
+ }
127
+ else {
128
+ throw new Error("No upstream server specified. Use either:\n" +
129
+ " --upstream-url <url> for HTTP/SSE servers\n" +
130
+ " -- <command> for stdio servers");
35
131
  }
36
132
  return {
37
133
  patterns,
38
- upstreamCommand,
134
+ transportConfig,
39
135
  };
40
136
  }
41
137
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpB,IAAI,iBAAiB,EAAE,CAAC;YACtB,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1B,SAAS;QACX,CAAC;QAED,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,iBAAiB,GAAG,IAAI,CAAC;YACzB,SAAS;QACX,CAAC;QAED,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5C,SAAS;QACX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C;QAED,eAAe,GAAG;YAChB,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,eAAe;YACxB,GAAG,EAAE,OAAO,CAAC,GAA6B;SAC3C,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,6CAA6C;YAC3C,+CAA+C;YAC/C,kCAAkC,CACrC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,QAAQ;QACR,eAAe;KAChB,CAAC;AACJ,CAAC"}
package/dist/filter.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FilterPattern } from "./cli.js";
1
+ import { FilterPattern } from "./types.js";
2
2
  export declare class Filter {
3
3
  private patterns;
4
4
  private hasIncludePatterns;
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,qBAAa,MAAM;IAGL,OAAO,CAAC,QAAQ;IAF5B,OAAO,CAAC,kBAAkB,CAAU;gBAEhB,QAAQ,EAAE,aAAa,EAAE;IAI7C,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAepC,UAAU,CAAC,CAAC,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE;CAGxD"}
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,qBAAa,MAAM;IAGL,OAAO,CAAC,QAAQ;IAF5B,OAAO,CAAC,kBAAkB,CAAU;gBAEhB,QAAQ,EAAE,aAAa,EAAE;IAI7C,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAepC,UAAU,CAAC,CAAC,SAAS;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE;CAGxD"}
package/dist/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from "child_process";
3
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5
3
  import { parseArgs } from "./cli.js";
6
4
  import { Filter } from "./filter.js";
7
5
  import { ProxyServer } from "./proxy.js";
6
+ import { createClientTransport } from "./transport.js";
8
7
  async function main() {
9
8
  // Parse command line arguments
10
9
  const args = process.argv.slice(2);
@@ -13,12 +12,52 @@ async function main() {
13
12
  config = parseArgs(args);
14
13
  }
15
14
  catch (error) {
15
+ if (error.message === "help") {
16
+ console.log("Usage:");
17
+ console.log(" mcp-filter [options] -- <command> [args...] # stdio transport");
18
+ console.log(" mcp-filter [options] --upstream-url <url> # HTTP transport");
19
+ console.log("");
20
+ console.log("Options:");
21
+ console.log(" --exclude <pattern> Exclude items matching pattern");
22
+ console.log(" --include <pattern> Include items matching pattern");
23
+ console.log(" --upstream-url <url> Connect to HTTP/SSE server (mutually exclusive with --)");
24
+ console.log(" --transport <type> Transport type: stdio, http, sse (auto-detected if omitted)");
25
+ console.log(" --header <header> Add HTTP header (format: 'Key: Value', HTTP/SSE only)");
26
+ console.log(" --help, -h Show this help message");
27
+ console.log("");
28
+ console.log("Examples:");
29
+ console.log(" # Stdio transport (local servers)");
30
+ console.log(' mcp-filter --exclude "test*" -- npx tsx test-server.ts');
31
+ console.log("");
32
+ console.log(" # HTTP transport (remote servers)");
33
+ console.log(' mcp-filter --exclude "dangerous_*" --upstream-url https://mcp.notion.com/mcp');
34
+ console.log("");
35
+ console.log(" # SSE transport (deprecated, legacy servers)");
36
+ console.log(' mcp-filter --transport sse --upstream-url https://mcp.asana.com/sse');
37
+ process.exit(0);
38
+ }
16
39
  console.error(`Error: ${error.message}`);
17
- console.error("Usage: mcp-filter [--exclude <pattern>]... [--include <pattern>]... -- <upstream-command> [args...]");
40
+ console.error("");
41
+ console.error("Usage:");
42
+ console.error(" mcp-filter [options] -- <command> [args...] # stdio transport");
43
+ console.error(" mcp-filter [options] --upstream-url <url> # HTTP transport");
44
+ console.error("");
45
+ console.error("Options:");
46
+ console.error(" --exclude <pattern> Exclude items matching pattern");
47
+ console.error(" --include <pattern> Include items matching pattern");
48
+ console.error(" --upstream-url <url> Connect to HTTP/SSE server (mutually exclusive with --)");
49
+ console.error(" --transport <type> Transport type: stdio, http, sse (auto-detected if omitted)");
50
+ console.error(" --header <header> Add HTTP header (format: 'Key: Value', HTTP/SSE only)");
51
+ console.error("");
18
52
  console.error("Examples:");
19
- console.error(' mcp-filter --exclude "playwright*" -- npx @playwright/mcp');
20
- console.error(' mcp-filter --include "browser_navigate" --include "browser_screenshot" -- npx @playwright/mcp');
21
- console.error(' mcp-filter --include "browser_*" --exclude "browser_close" -- npx @playwright/mcp');
53
+ console.error(" # Stdio transport (local servers)");
54
+ console.error(' mcp-filter --exclude "test*" -- npx tsx test-server.ts');
55
+ console.error("");
56
+ console.error(" # HTTP transport (remote servers)");
57
+ console.error(' mcp-filter --exclude "dangerous_*" --upstream-url https://mcp.notion.com/mcp');
58
+ console.error("");
59
+ console.error(" # SSE transport (deprecated, legacy servers)");
60
+ console.error(' mcp-filter --transport sse --upstream-url https://mcp.asana.com/sse');
22
61
  process.exit(1);
23
62
  }
24
63
  console.error(`Starting MCP filter with ${config.patterns.length} pattern(s)`);
@@ -28,21 +67,17 @@ async function main() {
28
67
  if (hasInclude && hasExclude) {
29
68
  console.error("Note: Using rsync-style filtering - patterns evaluated in order, first match wins.");
30
69
  }
31
- // Spawn upstream server
32
- const upstreamProcess = spawnUpstream(config.upstreamCommand);
70
+ console.error(`Transport: ${config.transportConfig.type}`);
33
71
  // Create filter
34
72
  const filter = new Filter(config.patterns);
35
73
  // Create proxy server
36
74
  const proxy = new ProxyServer({
37
75
  name: "mcp-filter",
38
- version: "0.2.0",
76
+ version: "0.5.0",
39
77
  }, filter);
40
- // Connect client to upstream server via subprocess stdio
41
- const clientTransport = new StdioClientTransport({
42
- command: config.upstreamCommand[0],
43
- args: config.upstreamCommand.slice(1),
44
- stderr: "pipe",
45
- });
78
+ // Connect client to upstream server
79
+ // Transport factory handles creating the appropriate transport (stdio, http, sse)
80
+ const clientTransport = createClientTransport(config.transportConfig);
46
81
  await proxy.getClient().connect(clientTransport);
47
82
  console.error("Connected to upstream server");
48
83
  // Connect server to current process stdio (for the MCP client calling us)
@@ -52,31 +87,11 @@ async function main() {
52
87
  // Handle cleanup
53
88
  const cleanup = () => {
54
89
  console.error("Shutting down...");
55
- upstreamProcess.kill();
56
90
  process.exit(0);
57
91
  };
58
92
  process.on("SIGINT", cleanup);
59
93
  process.on("SIGTERM", cleanup);
60
94
  }
61
- function spawnUpstream(command) {
62
- const [cmd, ...args] = command;
63
- const proc = spawn(cmd, args, {
64
- stdio: ["pipe", "pipe", "pipe"],
65
- });
66
- // Forward stderr to our stderr
67
- proc.stderr.on("data", (data) => {
68
- process.stderr.write(data);
69
- });
70
- proc.on("error", (error) => {
71
- console.error(`Failed to start upstream server: ${error.message}`);
72
- process.exit(1);
73
- });
74
- proc.on("exit", (code) => {
75
- console.error(`Upstream server exited with code ${code}`);
76
- process.exit(code || 0);
77
- });
78
- return proc;
79
- }
80
95
  main().catch((error) => {
81
96
  console.error("Fatal error:", error);
82
97
  process.exit(1);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,KAAK,EAAkC,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAA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O,EAAE,OAAO;KACjB,EACD,MAAM,CACP,CAAC;IAEF,oCAAoC;IACpC,kFAAkF;IAClF,MAAM,eAAe,GAAG,qBAAqB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAEtE,MAAM,KAAK,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAE9C,0EAA0E;IAC1E,MAAM,eAAe,GAAG,IAAI,oBAAoB,EAAE,CAAC;IACnD,MAAM,KAAK,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACjD,OAAO,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAExC,iBAAiB;IACjB,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
2
+ import type { TransportConfig } from "./types.js";
3
+ /**
4
+ * Creates a client transport based on the provided configuration.
5
+ *
6
+ * @param config - The transport configuration (stdio, http, or sse)
7
+ * @returns A configured Transport instance
8
+ * @throws Error if the configuration is invalid or transport creation fails
9
+ */
10
+ export declare function createClientTransport(config: TransportConfig): Transport;
11
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAI1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAsDxE"}
@@ -0,0 +1,57 @@
1
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
2
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
3
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
+ /**
5
+ * Creates a client transport based on the provided configuration.
6
+ *
7
+ * @param config - The transport configuration (stdio, http, or sse)
8
+ * @returns A configured Transport instance
9
+ * @throws Error if the configuration is invalid or transport creation fails
10
+ */
11
+ export function createClientTransport(config) {
12
+ switch (config.type) {
13
+ case "stdio": {
14
+ if (config.command.length === 0) {
15
+ throw new Error("Stdio transport requires a command");
16
+ }
17
+ return new StdioClientTransport({
18
+ command: config.command[0],
19
+ args: config.command.slice(1),
20
+ env: config.env || process.env,
21
+ stderr: "inherit",
22
+ });
23
+ }
24
+ case "http": {
25
+ let url;
26
+ try {
27
+ url = new URL(config.url);
28
+ }
29
+ catch (e) {
30
+ throw new Error(`Invalid HTTP URL: ${config.url}`);
31
+ }
32
+ // Add custom headers to requestInit if provided
33
+ const requestInit = config.headers && Object.keys(config.headers).length > 0
34
+ ? { headers: config.headers }
35
+ : undefined;
36
+ return new StreamableHTTPClientTransport(url, { requestInit });
37
+ }
38
+ case "sse": {
39
+ console.warn("⚠️ WARNING: SSE transport is deprecated as of protocol version 2024-11-05. " +
40
+ "Consider using HTTP transport instead for better performance and compatibility.");
41
+ let url;
42
+ try {
43
+ url = new URL(config.url);
44
+ }
45
+ catch (e) {
46
+ throw new Error(`Invalid SSE URL: ${config.url}`);
47
+ }
48
+ return new SSEClientTransport(url);
49
+ }
50
+ default: {
51
+ // TypeScript exhaustiveness check
52
+ const _exhaustive = config;
53
+ throw new Error(`Unknown transport type: ${_exhaustive.type}`);
54
+ }
55
+ }
56
+ }
57
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAGnG;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAuB;IAC3D,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,IAAI,oBAAoB,CAAC;gBAC9B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC1B,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7B,GAAG,EAAE,MAAM,CAAC,GAAG,IAAK,OAAO,CAAC,GAA8B;gBAC1D,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;QACL,CAAC;QAED,KAAK,MAAM,CAAC,CAAC,CAAC;YACZ,IAAI,GAAQ,CAAC;YACb,IAAI,CAAC;gBACH,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,qBAAqB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YACrD,CAAC;YAED,gDAAgD;YAChD,MAAM,WAAW,GACf,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC;gBACtD,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE;gBAC7B,CAAC,CAAC,SAAS,CAAC;YAEhB,OAAO,IAAI,6BAA6B,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,OAAO,CAAC,IAAI,CACV,8EAA8E;gBAC5E,iFAAiF,CACpF,CAAC;YAEF,IAAI,GAAQ,CAAC;YACb,IAAI,CAAC;gBACH,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,oBAAoB,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YACpD,CAAC;YAED,OAAO,IAAI,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,kCAAkC;YAClC,MAAM,WAAW,GAAU,MAAM,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,2BAA4B,WAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,26 @@
1
+ export interface FilterPattern {
2
+ type: "include" | "exclude";
3
+ pattern: string;
4
+ }
5
+ export type TransportType = "stdio" | "http" | "sse";
6
+ export interface StdioConfig {
7
+ type: "stdio";
8
+ command: string[];
9
+ env?: Record<string, string>;
10
+ }
11
+ export interface HttpConfig {
12
+ type: "http";
13
+ url: string;
14
+ headers?: Record<string, string>;
15
+ }
16
+ export interface SseConfig {
17
+ type: "sse";
18
+ url: string;
19
+ headers?: Record<string, string>;
20
+ }
21
+ export type TransportConfig = StdioConfig | HttpConfig | SseConfig;
22
+ export interface FilterConfig {
23
+ patterns: FilterPattern[];
24
+ transportConfig: TransportConfig;
25
+ }
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,CAAC;AAEnE,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,eAAe,EAAE,eAAe,CAAC;CAClC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-filter",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "MCP server proxy to filter tools, resources, and prompts from upstream MCP servers",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,8 +9,17 @@
9
9
  "files": [
10
10
  "dist",
11
11
  "README.md",
12
+ "CHANGELOG.md",
12
13
  "LICENSE"
13
14
  ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "dev": "tsc --watch",
18
+ "test": "vitest run",
19
+ "test:watch": "vitest --watch",
20
+ "test:coverage": "vitest --coverage",
21
+ "prepublishOnly": "pnpm test && pnpm run build"
22
+ },
14
23
  "keywords": [
15
24
  "mcp",
16
25
  "model-context-protocol",
@@ -31,10 +40,10 @@
31
40
  "minimatch": "10.0.1"
32
41
  },
33
42
  "peerDependencies": {
34
- "@modelcontextprotocol/sdk": "1.0.0"
43
+ "@modelcontextprotocol/sdk": ">=1.10.0"
35
44
  },
36
45
  "devDependencies": {
37
- "@modelcontextprotocol/sdk": "1.0.4",
46
+ "@modelcontextprotocol/sdk": "1.22.0",
38
47
  "@types/node": "22.10.5",
39
48
  "@vitest/coverage-v8": "2.1.8",
40
49
  "typescript": "5.7.3",
@@ -43,12 +52,5 @@
43
52
  },
44
53
  "engines": {
45
54
  "node": ">=18"
46
- },
47
- "scripts": {
48
- "build": "tsc",
49
- "dev": "tsc --watch",
50
- "test": "vitest run",
51
- "test:watch": "vitest --watch",
52
- "test:coverage": "vitest --coverage"
53
55
  }
54
- }
56
+ }