MCPorter

0.9.0 · active · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically discover MCP servers and tools, and invoke a tool using the `createRuntime` and `createServerProxy` APIs. It lists all configured servers and then attempts to call a hypothetical `linear.createComment` tool, handling potential configuration issues.

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);

view raw JSON →