/** * Matimo MCP Server * * Exposes all Matimo tools via the Model Context Protocol. * Supports stdio (local/Claude Desktop) and HTTP (remote/Docker) transports. * * Architecture: * Client → MCP Protocol → MCPServer → MatimoInstance.execute() → Tool APIs * Secrets resolved via SecretResolverChain (env, dotenv, Vault, AWS SM) * HTTP mode protected by Bearer token (MATIMO_MCP_TOKEN) */ import { MatimoInstance } from '../matimo-instance.js'; import type { SecretResolverChainConfig } from './secrets/types.js'; export interface MCPServerOptions { /** Transport mode. Default: 'stdio' */ transport?: 'stdio' | 'http'; /** HTTP port. Default: 3000. Only used in HTTP mode. */ port?: number; /** Allowlist of tool names. If set, only these tools are exposed. */ tools?: string[]; /** Denylist of tool names. Excluded from exposure. */ excludeTools?: string[]; /** Secret resolver chain config. Default: env-only. */ secretResolver?: SecretResolverChainConfig; /** Bearer token for HTTP mode. Also reads MATIMO_MCP_TOKEN env var. If not set in HTTP mode, auto-generated. */ mcpToken?: string; /** Tool paths to load. Passed to MatimoInstance.init(). */ toolPaths?: string[]; /** Skill paths to load. Passed to MatimoInstance.init(). Each path is a directory containing skill subdirectories with SKILL.md files. */ skillPaths?: string[]; /** Auto-discover @matimo/* packages. Default: true */ autoDiscover?: boolean; /** Enable HTTPS. Requires cert+key or use selfSigned. Default: false */ https?: boolean; /** Path to TLS certificate file (PEM). Required if https=true and selfSigned=false. */ certPath?: string; /** Path to TLS private key file (PEM). Required if https=true and selfSigned=false. */ keyPath?: string; /** Auto-generate self-signed certificate. Default: false. Certs stored in .matimo/certs/ */ selfSigned?: boolean; /** Policy configuration for tool filtering. Creates a DefaultPolicyEngine. */ policyConfig?: import('../policy/types').PolicyConfig; /** Paths containing untrusted (agent-created) tools. Subject to policy validation on reload. */ untrustedPaths?: string[]; /** HMAC secret for approval manifest. */ approvalSecret?: string; /** Directory for .matimo-approvals.json. */ approvalDir?: string; /** * Trust `_matimo_approved: true` from MCP tool-call arguments as an * out-of-band approval. Defaults to false because MCP arguments are supplied * by the client/model and are not a server-side approval signal by themselves. */ trustClientApproval?: boolean; } export declare class MCPServer { private readonly options; private matimo; private resolverChain; private mcpServer; private httpServer; /** Filtered tools available for MCP registration */ private filteredTools; /** The active bearer token (explicit, env, or auto-generated) */ private activeToken; /** Registered skill resources, keyed by skill name, for lifecycle management */ private registeredSkillResources; /** Resolved auth secrets held in memory — never written to process.env */ private resolvedSecrets; constructor(options?: MCPServerOptions); /** Get the active bearer token (available after start()) */ getActiveToken(): string | null; /** * Hot-reload tools via MatimoInstance and re-register them on the MCP server. * In stdio mode, calls sendToolListChanged() to notify the connected client. */ reloadTools(): Promise; /** * Start the MCP server. * * 1. Initialize secret resolver chain * 2. Seed process.env with resolved secrets (for MatimoInstance compatibility) * 3. Initialize MatimoInstance with tools * 4. Register all tools on the MCP server * 5. Connect transport (stdio or HTTP) */ start(): Promise; /** * Resolve all auth-related secrets for tools and seed them into process.env. * This ensures MatimoInstance.injectAuthParameters() can find them. */ private seedEnvironmentSecrets; /** * Register (or re-register) all skills from `matimo` as MCP resources on `server`. * Removes any previously registered skill resources before adding the current set * so that this method is safe to call multiple times (e.g., from reloadTools). */ private registerSkillResources; /** * Create a new McpServer instance with all filtered tools registered. * Each call returns a fresh server — used per-session in HTTP mode. */ private createMcpServerWithTools; /** * Connect via stdio transport (for Claude Desktop, Cursor, etc.) */ private connectStdio; /** * Connect via HTTP/HTTPS transport with Bearer token auth. * Creates a new McpServer + transport per session to support multiple concurrent clients. * Auto-generates a bearer token if none is provided. */ private connectHttp; /** * Get TLS options for HTTPS mode. * Supports user-provided certs or auto-generated self-signed certs. */ private getTlsOptions; /** * Generate a self-signed TLS certificate using Node.js crypto. * Certs are cached in .matimo/certs/ for reuse across restarts. */ private generateSelfSignedCert; /** * Create a self-signed certificate using openssl CLI. * Throws if openssl is unavailable or fails — provide --cert and --key paths as an alternative. */ private createSelfSignedCertViaCli; /** * Gracefully stop the MCP server. */ stop(): Promise; /** Get the MatimoInstance (for testing) */ getMatimoInstance(): MatimoInstance | null; } /** * Factory function to create and start an MCP server. * Convenience for one-liner usage. */ export declare function createMCPServer(options?: MCPServerOptions): Promise; //# sourceMappingURL=mcp-server.d.ts.map