Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 5, 2025

This PR translates the DocumentDB MCP Server from Python to TypeScript, creating a complete TypeScript implementation in the ./mcp_ts directory with support for both stdio and HTTP transports.

Overview

The TypeScript MCP server provides the same functionality as the Python version while following TypeScript best practices and integrating with the Node.js ecosystem. The implementation uses the official @modelcontextprotocol/sdk and MongoDB Node.js driver.

Key Features

Complete Tool Set (25+ tools)

  • Database Tools: List databases, get statistics, database info, drop operations
  • Collection Tools: Collection statistics, rename, drop, sample documents
  • Document Tools: Full CRUD operations, aggregation pipelines, query operations
  • Index Tools: Create, list, drop indexes, usage statistics, current operations
  • Workflow Tools: Query optimization, enhanced database info for AI generation

Transport Support

  • stdio Transport (default): Standard input/output for MCP client integration
  • streamable-http Transport: HTTP server implementing MCP Streamable HTTP specification for browser-based clients and HTTP integrations

Architecture Highlights

  • Type Safety: Strict TypeScript configuration with comprehensive type definitions
  • Modern Node.js: ESM modules, async/await patterns, proper error handling
  • MCP Integration: Uses official @modelcontextprotocol/sdk for protocol compliance
  • MongoDB Driver: Official mongodb Node.js driver replacing PyMongo
  • Lifecycle Management: Proper MongoDB client connection management
  • Session Management: Complete session lifecycle for HTTP transport

Implementation Details

// Example tool usage
{
  "name": "find_documents",
  "arguments": {
    "db_name": "mydb",
    "collection_name": "users",
    "query": {"status": "active"},
    "limit": 10,
    "sort": {"created_at": -1}
  }
}

The server maintains the same tool interface as the Python version while providing enhanced TypeScript type safety and better integration with the existing codebase patterns.

Transport Configuration

stdio (Default)

TRANSPORT=stdio

streamable-http

TRANSPORT=streamable-http
HOST=localhost
PORT=8070

When using HTTP transport, the server provides:

  • Endpoint: http://localhost:8070/mcp
  • Methods: GET (SSE streams), POST (requests), DELETE (session termination)
  • Session Management: Automatic session ID generation and lifecycle
  • CORS Support: Browser-compatible cross-origin requests

Project Structure

mcp_ts/
├── src/
│   ├── main.ts              # Entry point
│   ├── server.ts            # MCP server setup and tool registration
│   ├── config.ts            # Environment configuration
│   ├── models/index.ts      # TypeScript interfaces
│   ├── context/documentdb.ts # MongoDB client lifecycle
│   └── tools/               # Tool implementations by category
│       ├── database.ts      # Database operations
│       ├── collection.ts    # Collection operations  
│       ├── document.ts      # Document CRUD operations
│       ├── index.ts         # Index management
│       └── workflow.ts      # Query optimization tools
├── package.json             # Dependencies and scripts
├── tsconfig.json           # TypeScript configuration
└── README.md               # Complete documentation

Dependencies Mapping

Python TypeScript/Node.js
mcp @modelcontextprotocol/sdk
pymongo mongodb (official driver)
uvicorn express + built-in HTTP server
httpx fetch (built-in)

The TypeScript implementation supports both stdio and HTTP transports as specified in the MCP SDK documentation.

Fixes #240.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Translate MCP Server to TypeScript Translate Python MCP Server to TypeScript Sep 5, 2025
Copilot AI requested a review from xingfan-git September 5, 2025 04:51
Copilot finished work on behalf of xingfan-git September 5, 2025 04:51
if (config.transport !== 'stdio') {
console.error('Note: Currently only stdio transport is implemented');
console.error('Falling back to stdio transport');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to support streamable-http, it is very important for our next steps

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added streamable-http transport support to the TypeScript MCP server. The implementation includes:

  • StreamableHTTPServerTransport using the official MCP SDK
  • Session management with proper lifecycle handling
  • Express server with CORS support for browser clients
  • Configurable via TRANSPORT environment variable
  • Runs on http://localhost:8070/mcp by default

You can now use either:

  • TRANSPORT=stdio (default, for MCP clients)
  • TRANSPORT=streamable-http (for HTTP/browser integration)

The server supports GET (SSE streams), POST (requests), and DELETE (session termination) methods as per the MCP specification.

Commit: a00b027

- Add express and cors dependencies for HTTP server functionality
- Implement StreamableHTTPServerTransport alongside existing stdio transport
- Support both stdio and streamable-http transport modes via TRANSPORT env var
- Add session management with proper lifecycle handling
- Update configuration and documentation for HTTP transport
- Server runs on configurable host:port when using streamable-http mode

Co-authored-by: xingfan-git <[email protected]>
Copilot AI changed the title Translate Python MCP Server to TypeScript Translate Python MCP Server to TypeScript with HTTP Transport Support Sep 8, 2025
Copilot AI requested a review from xingfan-git September 8, 2025 03:54
Copilot finished work on behalf of xingfan-git September 8, 2025 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Translate MCP Server to TypeScript

2 participants