MCPorter
MCPorter is a TypeScript runtime and CLI tool designed to facilitate interaction with Model Context Protocol (MCP) servers. It provides capabilities for zero-configuration discovery of MCP servers across various environments (local files, editors like Cursor/Claude/VS Code), one-command CLI generation for any server definition, and the creation of strongly typed tool clients. The library offers a composable API for programmatic access, handling aspects like OAuth caching, log tailing, and different transport mechanisms (HTTP, SSE, stdio). Currently at version `0.9.0`, MCPorter maintains a rapid release cadence, indicated by frequent minor and patch updates, continuously enhancing its functionality for 'code execution' workflows as envisioned by the Model Context Protocol. Its key differentiators include automated config merging, ergonomic API wrappers that apply JSON-schema defaults and validation, and robust support for ad-hoc and OAuth-backed connections.
Common errors
-
Error: Server "my-server-name" not found in configuration.
cause The specified MCP server ID does not exist in any discovered configuration file (e.g., `~/.mcporter/mcporter.json`, `config/mcporter.json`, or editor imports).fixVerify the server ID is correct. Run `npx mcporter list` to see available servers. If the server is external or ad-hoc, ensure it's properly added using `mcporter config add` or specified via ad-hoc CLI flags. -
Error: Auth required for server "my-oauth-server".
cause The MCP server requires OAuth authentication, but no valid token is present or it has expired.fixRun `npx mcporter auth my-oauth-server` to initiate the OAuth flow in your browser. If issues persist, try `npx mcporter auth my-oauth-server --reset` to clear existing credentials. -
Error: Cannot find module 'mcporter' from ... (or similar CJS `require` error)
cause MCPorter is primarily distributed as an ES Module, and direct `require()` calls in a CommonJS environment might fail, especially in newer Node.js versions or without proper transpilation.fixEnsure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`) and use `import { ... } from 'mcporter';` syntax. If you must use CommonJS, consider dynamic `import('mcporter')` or a build step to transpile. -
Command failed: mcporter call linear.create_comment issueId:ENG-123 body:'Looks good!' Error: Invalid argument value for 'body': ...
cause CLI argument parsing can be sensitive to syntax, especially with complex values, quotes, or when switching between flag-based and function-call styles.fixReview the specific error message for argument type/format mismatch. Ensure proper quoting for string values, especially those with spaces. Consider using the function-call syntax with explicit string literals or `--args` for JSON objects. Run `mcporter list <server> --schema` for expected argument types.
Warnings
- breaking MCPorter `v0.8.0` introduced changes to how static `Authorization` headers are handled once OAuth is active. Imported editor configurations can no longer override fresh OAuth tokens, which might break workflows relying on statically defined headers overriding dynamic tokens.
- gotcha MCPorter `v0.9.0` added per-server exact-name tool filtering via `allowedTools` and `blockedTools` in configuration. If tools unexpectedly disappear or calls fail, verify these new filtering options in your `mcporter.json` files.
- breaking OAuth credentials were centralized to `~/.mcporter/credentials.json` in `v0.7.0`. Older credential caches might become invalid or require migration.
- gotcha The CLI supports multiple call syntaxes, including colon-delimited flags (`issueId:ENG-123`) and function-call style (`linear.create_comment(issueId: "ENG-123")`). Inconsistent usage or special characters in arguments can lead to parsing errors.
- gotcha Ad-hoc server connections via CLI flags like `--http-url` or `--stdio` are ephemeral by default. If you intend to reuse them, they must be explicitly persisted.
- deprecated Legacy ad-hoc flags `--sse` and `--insecure` have been aliased to `--http-url` and `--allow-http` respectively in `v0.6.5`. While still functional, prefer the newer, more descriptive flags.
Install
-
npm install mcporter -
yarn add mcporter -
pnpm add mcporter
Imports
- createRuntime
const createRuntime = require('mcporter')import { createRuntime } from 'mcporter' - createServerProxy
import createServerProxy from 'mcporter'
import { createServerProxy } from 'mcporter' - CallResult
import { CallResult } from 'mcporter'import type { CallResult } from 'mcporter' - McpServer
import type { McpServer } from 'mcporter'
Quickstart
import { createRuntime, createServerProxy } from 'mcporter';
async function main() {
// Initialize the MCPorter runtime. It automatically discovers servers
// from ~/.mcporter/mcporter.json, config/mcporter.json, and editor imports.
const runtime = await createRuntime();
// List all discovered servers and their tools.
console.log('Discovered MCP servers and tools:');
const servers = await runtime.listServers();
for (const server of servers) {
console.log(`- ${server.id}: ${server.description || 'No description'}`);
const tools = await server.listTools();
if (tools.length > 0) {
console.log(' Tools:');
for (const tool of tools) {
console.log(` - ${tool.name}: ${tool.description || 'No description'}`);
}
} else {
console.log(' No tools found.');
}
}
// Example: Interact with a specific server and tool.
// This assumes a server named 'linear' and a tool 'create_comment' exists for demonstration.
// Adjust server ID and tool name based on your MCPorter configuration (e.g., ~/.mcporter/mcporter.json).
try {
const linearServer = await runtime.getServer('linear');
if (linearServer) {
const linearProxy = createServerProxy(linearServer);
// Call the tool with strongly typed arguments.
const result = await linearProxy.createComment({
issueId: 'ENG-123',
body: 'Looks good from MCPorter programmatic API!',
});
console.log('\nResult from linear.createComment:');
console.log(await result.markdown());
} else {
console.log('\nServer "linear" not found in configuration. Skipping tool call example.');
}
} catch (error) {
console.error('\nError calling tool:', error);
console.log('Ensure you have a "linear" server configured (e.g., via ~/.mcporter/mcporter.json)');
console.log('and that the "create_comment" tool exists and is accessible.');
}
}
main().catch(console.error);