Appearance
MCP Server Examples
Real-world examples of MCP servers on Universal API.
Echo Server (Minimal)
The simplest possible MCP server — great for testing:
javascript
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
const { z } = require("zod");
function createMcpServer() {
const server = new McpServer({ name: "echo", version: "1.0.0" });
server.registerTool("echo", {
title: "Echo",
description: "Echo back the provided message",
inputSchema: { message: z.string().describe("The message to echo back") }
}, async ({ message }) => ({
content: [{ type: "text", text: `Echo: ${message}` }]
}));
return server;
}
module.exports = { createMcpServer };Web Search Server (SerpAPI)
A server that provides Google search, news, and Reddit search:
javascript
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
const { z } = require("zod");
function createMcpServer() {
const server = new McpServer({ name: "serpapi", version: "1.0.0" });
server.registerTool("google_search", {
title: "Google Search",
description: "Search Google and get structured results",
inputSchema: {
query: z.string().describe("Search query"),
num: z.number().optional().describe("Number of results (default: 10)")
}
}, async ({ query, num = 10 }) => {
const apiKey = process.env.SERPAPI_KEY;
if (!apiKey) {
return { content: [{ type: "text", text: "Error: SERPAPI_KEY not configured" }] };
}
const url = `https://serpapi.com/search.json?q=${encodeURIComponent(query)}&num=${num}&api_key=${apiKey}`;
const response = await fetch(url);
const data = await response.json();
const results = (data.organic_results || []).map((r, i) => ({
position: i + 1,
title: r.title,
link: r.link,
snippet: r.snippet
}));
return {
content: [{ type: "text", text: JSON.stringify({ query, resultCount: results.length, results }) }]
};
});
return server;
}
module.exports = { createMcpServer };Document Analysis Server (AWS Textract)
Extract text, tables, and forms from documents:
javascript
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
const { z } = require("zod");
const https = require("https");
function createMcpServer() {
const server = new McpServer({ name: "aws-textract", version: "1.0.0" });
server.registerTool("detect_text", {
title: "Detect Text",
description: "Extract text from a document image using AWS Textract",
inputSchema: {
document_bytes: z.string().describe("Base64-encoded document (PNG, JPEG, PDF)")
}
}, async ({ document_bytes }) => {
// Uses AWS SDK via the platform's credentials
const AWS = require("aws-sdk");
const textract = new AWS.Textract({ region: "us-east-1" });
const result = await textract.detectDocumentText({
Document: { Bytes: Buffer.from(document_bytes, "base64") }
}).promise();
const lines = result.Blocks
.filter(b => b.BlockType === "LINE")
.map(b => ({ text: b.Text, confidence: b.Confidence }));
return {
content: [{ type: "text", text: JSON.stringify({
text: lines.map(l => l.text).join("\n"),
lineCount: lines.length,
lines
})}]
};
});
return server;
}
module.exports = { createMcpServer };Server with Resources and Prompts
A complete server showing all three MCP capabilities:
javascript
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
const { z } = require("zod");
function createMcpServer() {
const server = new McpServer({ name: "complete-example", version: "1.0.0" });
// Tool
server.registerTool("calculate", {
title: "Calculate",
description: "Evaluate a math expression",
inputSchema: { expression: z.string().describe("Math expression like '2 + 2'") }
}, async ({ expression }) => {
try {
const result = Function('"use strict"; return (' + expression + ')')();
return { content: [{ type: "text", text: JSON.stringify({ expression, result }) }] };
} catch (e) {
return { content: [{ type: "text", text: `Error: ${e.message}` }] };
}
});
// Resource
server.resource(
"capabilities",
"complete-example://capabilities",
{ description: "List of server capabilities", mimeType: "application/json" },
async (uri) => ({
contents: [{
uri: uri.href,
mimeType: "application/json",
text: JSON.stringify({
tools: ["calculate"],
prompts: ["math-tutor"],
version: "1.0.0"
})
}]
})
);
// Prompt
server.prompt(
"math-tutor",
"Get help solving a math problem step by step",
{ problem: z.string().describe("The math problem to solve") },
async ({ problem }) => ({
messages: [{
role: "user",
content: {
type: "text",
text: `Please solve this math problem step by step, showing your work:\n\n${problem}\n\nUse the calculate tool to verify your answer.`
}
}]
})
);
return server;
}
module.exports = { createMcpServer };Tips for Building Servers
- Start simple — Get one tool working, then add more
- Test with curl before connecting to Claude/Cline
- Check for API keys early and return clear error messages
- Use
JSON.stringify()for structured responses - Add
.describe()to all Zod schema fields — the AI reads these