SWAPI MCP Server
Enables LLMs and clients to search for Star Wars characters, planets, and films by exposing SWAPI as MCP tools.
README
SWAPI MCP Server
A Model Context Protocol (MCP) server that wraps the Star Wars API (SWAPI) as MCP tools, allowing LLMs and clients to search for Star Wars characters, planets, and films.
Features
- MCP-compliant server using the official TypeScript SDK
- Exposes three tools:
search_character: Search for a Star Wars character by nameget_planet: Get detailed planet info by IDget_film: Get detailed film info by ID
- Supports both HTTP (stateless, streamable) and stdio transports
Code Structure
index.ts: Main entry point. Sets up the MCP server, registers tools, and configures HTTP and stdio transports.test-client/: Example OpenAI client that demonstrates how to call the MCP server as a tool from an LLM.
Tool Details
search_character
- Input:
{ name: string } - Description: Searches SWAPI for characters matching the given name.
- Returns: JSON-formatted list of matching characters.
get_planet
- Input:
{ id: string } - Description: Fetches detailed info for a planet by its SWAPI ID.
- Returns: JSON-formatted planet details.
get_film
- Input:
{ id: string } - Description: Fetches detailed info for a film by its SWAPI ID.
- Returns: JSON-formatted film details.
How It Works
- Uses the @modelcontextprotocol/sdk to create an MCP server.
- Each tool is registered with an input schema (using zod) and an async handler that fetches data from SWAPI.
- The server can be accessed via HTTP POST requests to
/mcpor via stdio (for CLI clients).
Running the Server
Prerequisites
- Node.js v18 or newer
- npm
Install dependencies
npm install
Run in HTTP mode (default)
npx ts-node index.ts
- The server will listen on
http://localhost:3000/mcp(or the port set in thePORTenvironment variable).
Run in stdio mode (for CLI clients)
- The server automatically starts a stdio transport for CLI-based MCP clients.
Example HTTP Request
List tools:
curl -X POST http://localhost:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":0,"method":"tools/list","params":{}}'
Search for a character:
curl -N -X POST http://localhost:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "search_character",
"arguments": { "name": "Luke" }
},
"id": 1
}'
Get a planet by ID:
curl -N -X POST http://localhost:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_planet",
"arguments": { "id": "1" }
},
"id": 2
}'
Get a film by ID:
curl -N -X POST http://localhost:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_film",
"arguments": { "id": "1" }
},
"id": 3
}'
Test Client: OpenAI + MCP Integration
The test-client/ directory contains an example script (swapi-client.ts) that demonstrates how to call the MCP server as a tool from an OpenAI LLM (e.g., GPT-4o-mini).
How it works
- Uses the OpenAI SDK and MCP tool integration.
- Registers the MCP server as a tool for the LLM.
- Sends a prompt/question to the LLM, which can call the MCP tools to answer.
Example: test-client/swapi-client.ts
// node --loader ts-node/esm ./swapi-client.ts
import 'dotenv/config';
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
const tools = [
{
type: "mcp" as const,
server_label: 'swapi',
server_url: 'http://localhost:3000/mcp', // this has to be accessible from your LLM
require_approval: 'never' as const,
},
];
const resp = await openai.responses.create({
model: 'gpt-4o-mini',
tools,
input: 'Where was Luke Skywalker born and how tall is he?',
});
console.log(resp.output_text);
Running the test client
- Install dependencies:
cd test-client npm install - Set your OpenAI API key in a
.envfile:OPENAI_API_KEY=sk-... - Start the MCP server (in the parent directory):
npx ts-node index.ts - Run the test client:
node --loader ts-node/esm ./swapi-client.ts
- You should see the LLM's answer, which may include information fetched from the SWAPI MCP tools.
- You can also point the
server_urlto a public ngrok URL if you want to test from outside localhost.
Notes
- The server is stateless for HTTP requests (no session management).
- CORS is enabled for the
mcp-session-idheader. - For more details on MCP, see the TypeScript SDK documentation.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.