0:00
/
0:00
Transcript

How to Build and Publish an MCP Server

A Detailed Guide
1

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:

Buy the Scripts


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:

  1. MCP Servers: https://github.com/modelcontextprotocol/servers

  2. PyPi MCP: https://pypi.org/project/mcp/#running-the-standalone-mcp-development-tools

  3. 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

  1. Initialize project with npm

  2. Install MCP SDK dependency

  3. Create server script with defined tools

  4. Configure package.json with bin parameter pointing to server file

  5. Test using MCP inspector

  6. 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

  1. Initialize with uv init using Hatchling backend

  2. Add MCP dependency with uv add

  3. Create entry point via main.py

  4. Configure pyproject.toml with dependencies and build settings

  5. Test locally with uv run

  6. Publish to PyPI

Advanced Implementation: Document Reader

Created a document conversion service that:

  1. Converts PDFs to Markdown using marker-pdf

  2. Converts DOCX files using PyPandoc

  3. Enables reading specific line ranges from documents

Key components:

  1. PDF conversion tool using marker-pdf library

  2. Modified Anthropic's file system MCP to support line-range reading

  3. Integration with both Cursor and Claude Desktop

Technical requirements:

  1. Python with UV installed

  2. Pandoc system dependency

  3. Transformers library pinned to version compatible with marker-pdf

  4. Full system PATH when running in Claude Desktop

Distribution Methods

Three ways to distribute MCP servers:

  1. Local development:

uv run -m {package_name}

  1. GitHub repository:

uvx git+https://github.com/org/repo#subdirectory={path}

  1. 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.

Discussion about this video

User's avatar