MCP文件传输代理

mcp-file-proxy 是一个 stdio 转 HTTP 的 MCP 代理,用于在本地 MCP 客户端与远程 MCP 服务器之间传输文件;它会识别输入 schema 中的二进制参数,读取本地文件并以 base64 流式转发,适用于需要向远程工具上传文档或二进制数据的开发场景。

  • by dongit-org
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 dongit-org/mcp-file-proxy

使用说明

mcp-file-proxy

A stdio-to-HTTP MCP proxy that lets MCP clients send local files to remote MCP servers.

MCP clients like Claude Desktop run locally but connect to remote servers over HTTP. When a tool expects binary file data, the client has no way to read a local file and send it. This proxy sits in between: it detects file parameters, reads the files from disk, streams them as base64, and forwards the encoded data to the remote server. All other requests (resources, prompts, non-file tool calls) are forwarded as-is.

How file detection works

The proxy inspects each tool's inputSchema when it receives a tools/list response from the remote server. Any parameter with "format": "binary" is treated as a file parameter. When that tool is called, the proxy checks if the argument value is a local file path, and if that's the case, it reads and base64-encodes the file before forwarding. Values that are already base64-encoded are passed through unchanged.

To mark a parameter as binary on your server, set format to "binary" in the tool's input schema:

{
  "name": "upload-document",
  "inputSchema": {
    "type": "object",
    "properties": {
      "file": {
        "type": "string",
        "format": "binary",
        "description": "The document to upload"
      },
      "file_name": {
        "type": "string",
        "description": "document filename"
      }
    }
  }
}

The proxy will prepend "Provide a file path." to the description of binary parameters so the client knows to supply a path.

If an optional <param>_name string parameter is declared alongside a binary param (e.g. file_name next to file), the proxy hides it from the client and auto-fills it with the file's basename on each call, so the server can store the original filename.

Configuration

Add to your MCP client config:

{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["@dongit/mcp-file-proxy"],
      "env": {
        "MCP_URL": "https://example.com/mcp",
        "MCP_HEADERS": "{\"Authorization\": \"Bearer your-token\"}"
      }
    }
  }
}

Environment variables

Variable Required Description
MCP_URL Yes URL of the remote MCP server
MCP_HEADERS No JSON object of headers to send with requests
MCP_CLIENT_CERT No Path to a PEM client certificate for mutual TLS (requires MCP_CLIENT_KEY)
MCP_CLIENT_KEY No Path to the PEM private key for the client certificate
MCP_CLIENT_KEY_PASSPHRASE No Passphrase for the client key, if the key file is encrypted
MCP_CA_CERT No Path to a PEM CA bundle used to verify the server certificate

Flags

Flag Description
--accept-insecure-certs Disable TLS certificate verification (for self-signed certs in dev)

Mutual TLS (client certificates)

If the remote server requires mutual TLS, point MCP_CLIENT_CERT and MCP_CLIENT_KEY at your PEM-encoded certificate and private key. When the server's certificate is signed by a private CA, also set MCP_CA_CERT so the proxy can verify it without disabling certificate checks:

{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["@dongit/mcp-file-proxy"],
      "env": {
        "MCP_URL": "https://example.com/mcp",
        "MCP_HEADERS": "{\"Authorization\": \"Bearer your-token\"}",
        "MCP_CLIENT_CERT": "/path/to/client.crt",
        "MCP_CLIENT_KEY": "/path/to/client.key",
        "MCP_CA_CERT": "/path/to/ca.crt"
      }
    }
  }
}

Note: setting MCP_CA_CERT replaces Node's default trust store rather than extending it — the proxy will then only trust servers whose chain leads to a CA in that bundle. If you need both a private CA and the public CAs, concatenate them into one bundle file.

Only PEM files are supported. If your credentials came as a PKCS#12 bundle (.p12/.pfx), convert it first:

openssl pkcs12 -in client.p12 -clcerts -nokeys -out client.crt
openssl pkcs12 -in client.p12 -nocerts -nodes -out client.key