Couchbase星球大战向量搜索
STDIO使用Couchbase向量搜索星球数据
使用Couchbase向量搜索星球数据
This project demonstrates the implementation of a Model Context Protocol (MCP) server that provides semantic search capabilities for Star Wars planets using Couchbase's vector search functionality.
The Model Context Protocol (MCP) is a standardized way for AI models to interact with external tools and data sources. This implementation creates an MCP server that allows AI models to:
The server implements two main MCP tools:
{ tools: [ { name: "fetch_planet_name", description: "Fetch a Star Wars planet by name", inputSchema: // ... schema for planet name }, { name: "find_planets_which_are_similar", description: "Find similar planets by name to the given name", inputSchema: // ... schema for planet name } ] }
These tools can be discovered and called by AI models that support the Model Context Protocol.
The implementation uses Couchbase's vector search capabilities to find similar planets:
embedding
field containing a vector representation of the planet's characteristicsCOUCHBASE_URL=
COUCHBASE_USERNAME=
COUCHBASE_PASSWORD=
COUCHBASE_BUCKET=
COUCHBASE_SCOPE=
COUCHBASE_COLLECTION=
Each planet document should follow this structure:
interface StarWarsCharacter { name: string; rotation_period: string; orbital_period: string; diameter: string; climate: string; gravity: string; terrain: string; surface_water: string; population: string; residents: string[]; films: string[]; created: string; edited: string; url: string; embedding?: number[]; // Vector embedding for similarity search }
Create a vector search index in Couchbase named vector-search-index
that indexes the embedding
field.
Start the server:
npm start
The server will listen for MCP requests via stdin/stdout.
AI models can interact with the server using these example queries:
// Fetch planet details { "name": "fetch_planet_name", "arguments": { "name": "Tatooine" } } // Find similar planets { "name": "find_planets_which_are_similar", "arguments": { "name": "Tatooine" } }