Building MCP Servers with Python and JS/TS
It’s tricky! and it took me quite a bit longer to make this video than expected - I kept running into issues with packages, environments and paths.
It’s also confusing that there are multiple ways to run an MCP service (via the mcp library, or directly using uv). “uvx” itself is very convenient - analogous to “npx” it will install dependencies in a temporary environment and run the package/server. But “uvx” is quite finicky and LLMs are not familiar with it because it’s new.
All in all, this basic run down of setting up simple and complex Python and JS/TS MCP servers should help quite a bit.
I also cover an interesting use case, where I use MCP servers to read PDF files, by first converting them and then reading them.
Cheers, Ronan
P.S. The scripts are in the ADVANCED-inference repo:
Trelis Links:
🤝 Are you a talented developer? Work for Trelis
💡 Need Technical or Market Assistance? Book a Consult Here
💸 Starting a New Project/Venture? Apply for a Trelis Grant
Video Links:
MCP Servers: https://github.com/modelcontextprotocol/servers
PyPi MCP: https://pypi.org/project/mcp/#running-the-standalone-mcp-development-tools
NPM MCP: https://www.npmjs.com/package/@modelcontextprotocol/sdk
TIMESTAMPS:
0:00 How to create and deploy an MCP server?
0:35 Buy the scripts at trelis.com/ADVANCED-inference
1:18 Repo overview
2:29 Build and deploy a javascript server to npm
12:05 Adjustments for a Typescript MCP server
12:50 Build and deploy a python server to PyPI
29:57 Advanced Python and JS / TS MCP Services
31:26 Python Document Converter MCP
45:02 How to edit a typescript MCP server and re-publish it to npm
54:50 Why building MCP services is tricky
Building and Publishing Model Context Protocol (MCP) Servers
MCP enables connecting language models to tools like GitHub, LinkedIn, Gmail, and document readers. This guide covers creating MCP servers in Python and JavaScript/TypeScript, with examples ranging from basic to advanced implementations.
Simple Server Examples
JavaScript/TypeScript Implementation
Initialize project with npm
Install MCP SDK dependency
Create server script with defined tools
Configure package.json with bin parameter pointing to server file
Test using MCP inspector
Publish to npm repository
Key steps for JS/TS setup:
npm init
npm install @anthropic-ai/model-context-protocol
// Create server script
// Add bin field to package.json
npx @anthropic-ai/model-context-protocol-inspector
Python Implementation
Initialize with uv init using Hatchling backend
Add MCP dependency with uv add
Create entry point via main.py
Configure pyproject.toml with dependencies and build settings
Test locally with uv run
Publish to PyPI
Advanced Implementation: Document Reader
Created a document conversion service that:
Converts PDFs to Markdown using marker-pdf
Converts DOCX files using PyPandoc
Enables reading specific line ranges from documents
Key components:
PDF conversion tool using marker-pdf library
Modified Anthropic's file system MCP to support line-range reading
Integration with both Cursor and Claude Desktop
Technical requirements:
Python with UV installed
Pandoc system dependency
Transformers library pinned to version compatible with marker-pdf
Full system PATH when running in Claude Desktop
Distribution Methods
Three ways to distribute MCP servers:
Local development:
uv run -m {package_name}
GitHub repository:
uvx git+https://github.com/org/repo#subdirectory={path}
Package repositories:
# PyPI
uvx {package_name}
# npm
npx @org/{package_name}
The implementation supports security features like allowed path restrictions and handles environment configuration for dependency management.
Share this post