Learn how to set up and build MCP servers with API integration using this comprehensive step-by-step guide
Model Context Protocol (MCP) is an open-standard protocol that serves as a universal adapter for AI applications, enabling seamless integration with various data sources and tools. The MCP server in this guide will demonstrate how to integrate external API services into the MCP ecosystem, specifically focusing on enhancing AI applications like Claude Desktop.
This MCP server supports real-time API calls from external providers, allowing developers to extend the functionality of their AI applications without writing custom integration code. Key features include:
The architecture of this MCP server is designed to be modular and extensible, allowing seamless integration with different APIs. The server uses TypeScript for implementation, ensuring robustness and maintainability.
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
graph TD
A[AI Application] --> B[MCP Client] --> C[MCP Protocol] --> D[MCP Server] --> E[Data Source/Tool]
A[AI Application] --> F[API Response]
style A fill:#e1f5fe
style D fill:#f3e5f5
style E fill:#b4f5c8
Clone this repository into a designated folder for easy organization:
mkdir mcp-servers
cd mcp-servers
git clone https://github.com/modelcontextprotocol/server-coding-demo.git
Navigate to the src
directory and review the following files:
AI applications like Claude Desktop benefit greatly from MCP servers. Here are two realistic use cases:
Integrate real-time weather updates into your chat application to provide users with accurate forecasts:
// demo.ts
import * as fetch from 'node-fetch';
const API_KEY = 'your-api-key';
const URL = `https://api.openweathermap.org/data/2.5/weather?q=New%20York&appid=${API_KEY}`;
async function getWeather() {
const response = await fetch(URL);
const data = await response.json();
return data.main.temp;
}
export default async (args: any) => {
// Process user input and call the API
try {
const temperature = await getWeather();
return `The current temperature in New York is ${temperature}°C.`;
} catch (error) {
return "Failed to retrieve weather data.";
}
};
Fetch and display the latest news articles based on user input:
// demo.ts
import * as fetch from 'node-fetch';
const API_KEY = 'your-api-key';
const URL = `https://newsapi.org/v2/top-headlines?country=us&apiKey=${API_KEY}`;
async function getNews() {
const response = await fetch(URL);
const data = await response.json();
return data.articles.map((article) => article.title).join('\n');
}
export default async (args: any) => {
// Process user input and call the API
try {
const titles = await getNews();
return `The latest news in USA:\n${titles}`;
} catch (error) {
return "Failed to retrieve news data.";
}
};
This server is compatible with multiple MCP clients, including Claude Desktop, Continue, Cursor, and more. The MCP Client Compatibility Matrix
highlights which features are fully supported:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✔ | ✔ | ✔ | Full Support |
Continue | ✔ | ✔ | ✔ | Partially Supported |
Cursor | ❌ | ✔ | ❌ | Tools Only |
The performance and compatibility matrix ensures that this MCP server can handle a wide range of APIs and data sources:
Advanced configuration options help ensure the security and reliability of your MCP integration. Key settings include:
Use .env
files to store sensitive information like API keys:
RAPIDAPI_KEY=XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX-XXX
Implement SSL/TLS for secure data transmission, use rate limiting to prevent abuse, and log detailed errors for debugging purposes.
demo.ts
file to integrate any API of your choice.npm run build
and then launch the Chat application with updated configurations.To contribute to the development and maintenance of this MCP server:
git clone https://github.com/<your-fork>/server-coding-demo.git
npm install
npm run build
Explore more resources and tools for building and integrating MCP servers:
By following these guidelines, you can effectively integrate external APIs into your AI applications and enhance their functionality through the Model Context Protocol.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods