Skip to main content
Glama
index.ts2.97 kB
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { loadConfig } from './config.js'; import { ContextStreamClient } from './client.js'; import { registerTools } from './tools.js'; import { registerResources } from './resources.js'; import { registerPrompts } from './prompts.js'; import { SessionManager } from './session-manager.js'; const VERSION = '0.3.4'; function printHelp() { // Keep help output on stdout so it is visible when run via npx console.log(`ContextStream MCP Server (contextstream-mcp) v${VERSION} Usage: npx -y @contextstream/mcp-server contextstream-mcp Environment variables: CONTEXTSTREAM_API_URL Base API URL (e.g. https://api.contextstream.io) CONTEXTSTREAM_API_KEY API key for authentication (or use CONTEXTSTREAM_JWT) CONTEXTSTREAM_JWT JWT for authentication (alternative to API key) CONTEXTSTREAM_WORKSPACE_ID Optional default workspace ID CONTEXTSTREAM_PROJECT_ID Optional default project ID Examples: CONTEXTSTREAM_API_URL="https://api.contextstream.io" \\ CONTEXTSTREAM_API_KEY="your_api_key" \\ npx -y @contextstream/mcp-server Notes: - When used from an MCP client (e.g. Codex, Cursor, VS Code), set these env vars in the client's MCP server configuration. - The server communicates over stdio; logs are written to stderr.`); } async function main() { const args = process.argv.slice(2); if (args.includes('--help') || args.includes('-h')) { printHelp(); return; } if (args.includes('--version') || args.includes('-v')) { console.log(`contextstream-mcp v${VERSION}`); return; } const config = loadConfig(); const client = new ContextStreamClient(config); const server = new McpServer({ name: 'contextstream-mcp', version: VERSION, }); // Create session manager for auto-context feature // This enables automatic context loading on the FIRST tool call of any session const sessionManager = new SessionManager(server, client); // Register all MCP components with auto-context enabled registerTools(server, client, sessionManager); registerResources(server, client, config.apiUrl); registerPrompts(server); // Log startup info (to stderr to not interfere with stdio protocol) console.error(`ContextStream MCP server starting...`); console.error(`API URL: ${config.apiUrl}`); console.error(`Auth: ${config.apiKey ? 'API Key' : config.jwt ? 'JWT' : 'None'}`); console.error(`Auto-Context: ENABLED (context loads on first tool call)`); // Start stdio transport (works with Claude Code, Cursor, VS Code MCP config, Inspector) const transport = new StdioServerTransport(); await server.connect(transport); console.error('ContextStream MCP server connected and ready'); } main().catch((err) => { console.error('ContextStream MCP server failed to start:', err?.message || err); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/contextstream/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server