Skip to main content

What You’ll Build

A simple MCP server with one tool that you can deploy and register on the Context Marketplace. No external API keys required.
Already have an API you want to unbundle? Skip to the AI-Assisted Builder section in the Build & List guide for a faster workflow using Cursor or Claude.
When you move from this toy example to real third-party APIs, add _meta.rateLimit hints to your tools. See Tool Metadata.

Prerequisites

Before starting, ensure you have:
  • Node.js 18+: check with node --version
  • pnpm (recommended): install with npm install -g pnpm
  • A code editor: VS Code, Cursor, etc.

Step 1: Create Your Project

Open your terminal and run these commands:
Create a tsconfig.json:
Update your package.json to add the start script:

Step 2: Write Your MCP Server (Without Security)

We’ll build the server without the security middleware first so you can test everything locally. You’ll add security before deploying. Create server.ts:
This toy tool has no parameters, but real tools should add default and examples to inputSchema properties. The AI reads these during orchestration to generate correct arguments. Without them, it guesses from the description alone, leading to more retries. See Build & List Your Tool for the full pattern.

Step 3: Test Locally

Start your server:
You should see:
Test the health endpoint:
Test initialize (start a session):
Copy the sessionId from the response. Test tools/call (execute your tool):
You should get a random quote back. Your tool works locally.

Step 4: Add Security Middleware

Before deploying, you must add the Context security middleware. This ensures only paid requests from the Context Platform can execute your tools. Update your server.ts:
Don’t skip this step! Without the middleware, anyone can call your tools for free. The middleware verifies that requests come from the Context Platform with valid payment.
After adding the middleware, tools/call will return {"error":"Unauthorized"} when tested locally. This is expected: it means security is working. You can always comment out verifyContextAuth temporarily for local testing.

Step 5: Deploy to Railway

HTTPS is required. The Context Platform will only connect to HTTPS endpoints. Railway, Vercel, and similar platforms provide HTTPS automatically. If you’re self-hosting, you’ll need to set up HTTPS (e.g., with Caddy or nginx).
1

Push to GitHub

Create a new repository and push your code:
2

Deploy on Railway

  1. Go to railway.app and sign in with GitHub
  2. Click “New Project”“Deploy from GitHub repo”
  3. Select your my-first-mcp repository
  4. Railway auto-detects Node.js and deploys
3

Configure Start Command

In Railway dashboard:
  1. Go to your service Settings
  2. Set Start Command to: pnpm start
  3. Railway will redeploy automatically
4

Get Your Public URL

  1. Go to SettingsNetworking
  2. Click “Generate Domain”
  3. Copy your URL (e.g., https://my-first-mcp-production.up.railway.app)
Test your deployed server:

Step 6: Register on Context Marketplace

1

Go to Contribute Page

2

Fill in the Form

3

Auto-Discovery

Click submit. Context will call your /mcp endpoint to discover your tools via listTools().
4

Stake USDC

All tools require a minimum $10 USDC stake. This is fully refundable with a 7-day withdrawal delay.

Step 7: Verify It Works

  1. Go to ctxprotocol.com
  2. In the chat, ask: “Get me an inspirational quote”
  3. The agent should discover and use your tool!

Updating Your Tool

When you add new endpoints or modify your MCP server, you need to refresh the tool listing on Context.
1

Deploy Your Changes

Push your updated code to your deployment (Railway, VPS, etc.)
2

Refresh Skills

  1. Go to ctxprotocol.com/developer/tools
  2. Find your tool and click “Refresh Skills”
  3. Context will re-call listTools() to discover your new/updated tools
3

Update Description (Optional)

If you’ve added significant new functionality:
  1. Use the MCP Server Analysis Prompt to generate an updated description
  2. Edit your tool’s description in the Developer Tools page
Common mistake: Deploying new endpoints but forgetting to click “Refresh Skills”. Your new tools won’t appear in the marketplace until you refresh.

What’s Next?

Add Real Data

Connect to external APIs and build valuable tools

AI-Assisted Builder

Use Cursor or Claude to build complex MCP servers from API docs

Context Injection

Access user portfolio data in your tools

Handshake Architecture

Enable signatures, transactions, and OAuth

Troubleshooting

For a complete list of common errors and solutions, see the Troubleshooting Guide.
This means your security middleware is working correctly.After adding createContextMiddleware() (Step 4), local tools/call requests will return Unauthorized because they don’t have a valid JWT from the Context Platform.If testing locally:
  • Temporarily comment out verifyContextAuth in your endpoint handlers
  • Or test before adding the middleware (Step 3)
If deployed and registered but still getting Unauthorized:
  • Ensure your endpoint is HTTPS (not HTTP)
  • Verify the URL you registered matches your deployed server exactly
  • Check that your tool is actually registered at ctxprotocol.com/contribute
  • Check Node.js version: node --version (must be 18+)
  • Ensure all dependencies installed: pnpm install
  • Check for TypeScript errors: pnpm exec tsc --noEmit
  • Ensure package.json has "type": "module"
  • Check Railway logs for specific errors
  • Verify start command is pnpm start
  • Verify your /health endpoint returns 200
  • Test initialize and tools/list with curl (these don’t require auth)
  • Ensure HTTPS URL: HTTP endpoints will not work

Complete Project Structure

Your project should look like this:
Ready for more? Check out the complete server examples for production patterns including error handling, caching, and multiple tools.