vavanv/my_first_mcp_server
If you are the rightful owner of my_first_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server that provides tools for querying AI model information from a PostgreSQL database.
My First MCP Server
A Model Context Protocol (MCP) server that provides tools for querying AI model information from a PostgreSQL database. This server demonstrates how to build MCP tools that interact with a database using Prisma ORM.
Features
- Database Integration: Uses Prisma ORM with PostgreSQL to store and retrieve AI company and model data
- MCP Tools: Provides tools for querying AI company information:
getModelName: Retrieves all AI models from the databasegetReviews: Gets versions/reviews for a specific AI model by namegetChats: Retrieves all chat platforms and their informationgetChatsByCompany: Gets chat platforms by company name
- Type Safety: Built with TypeScript for better development experience
- Database Seeding: Includes comprehensive AI company data from CSV
Database Schema
The application uses a relational schema with three main entities:
Company Model
- id: Unique identifier (CUID)
- company: Company name (unique)
- description: Company description and details
- chats: One-to-many relationship with Chat model
- llms: One-to-many relationship with LLM model
- createdAt/updatedAt: Timestamps
Chat Model
- id: Unique identifier (CUID)
- chatbot: Chatbot name
- companyId: Foreign key reference to Company
- company: Relation to Company model
- createdAt/updatedAt: Timestamps
- Unique constraint: [chatbot, companyId]
LLM Model
- id: Unique identifier (CUID)
- llm: LLM model name
- specialization: LLM specialization/description
- companyId: Foreign key reference to Company
- company: Relation to Company model
- createdAt/updatedAt: Timestamps
- Unique constraint: [llm, companyId]
Prerequisites
- Node.js (v18 or higher)
- PostgreSQL database
- Yarn or npm package manager
Installation
- Clone the repository:
git clone <repository-url>
cd my_first_mcp_server
- Install dependencies:
yarn install
- Set up your environment variables by creating a
.envfile:
DATABASE_URL="postgresql://username:password@localhost:5432/your_database_name"
- Generate Prisma client:
yarn prisma:generate
- Run database migrations:
npx prisma migrate dev
- Seed the database with AI company data from CSV:
yarn prisma:seed
Usage
Development Mode
Start the server in development mode:
yarn server:dev
Building for Production
Build the TypeScript code:
yarn server:build
Testing with MCP Inspector
Test the server using the MCP Inspector:
yarn server:inspect
For development without authentication:
yarn server:inspect2
Database Management
- Prisma Studio: Open a web interface to view and edit database data:
yarn prisma:studio
- Generate Prisma Client: After schema changes:
yarn prisma:generate
Available Tools
getModelName
Retrieves all AI models from the database.
Parameters: None
Returns: JSON array of all AI models with their properties.
getReviews
Gets versions/reviews for a specific AI model.
Parameters:
modelName(string): The name of the model to get reviews for
Returns: JSON array of model versions for the specified model.
getChats
Retrieves all chat platforms and their information from the database.
Parameters: None
Returns: JSON array of all chat platforms with their properties.
getChatsByCompany
Gets chat platforms by company name.
Parameters:
company(string): The company name to search for
Returns: JSON array of chat platforms for the specified company.
Sample Data
The database is populated with comprehensive AI company data including:
- 22 unique companies (OpenAI, Google, Meta AI, Anthropic, etc.)
- Chat platforms (ChatGPT, Gemini, Claude, etc.)
- LLM models with specializations (GPT-4, PaLM 2, LLaMA, etc.)
Example data structure:
OpenAI:
- Chats: ChatGPT
- LLMs: GPT-3, GPT-3.5, GPT-4, GPT-4o, GPT-4o mini, GPT-4.5 Orion
Google:
- Chats: Gemini (formerly Bard)
- LLMs: BERT, PaLM 2, Gemini, Gemma
Anthropic:
- Chats: Claude
- LLMs: Claude, Claude 3, Claude 4.0 Opus Thinking
Project Structure
my_first_mcp_server/
├── server/
│ ├── server.ts # Main MCP server implementation
│ └── tools/
│ ├── index.ts # Tool registration exports
│ ├── getCompanies.ts # Tool for getting all companies
│ ├── getChats.ts # Tool for getting chats by company
│ └── getLLMs.ts # Tool for getting LLMs by company
├── src/
│ └── lib/
│ └── prisma.ts # Prisma client configuration
├── prisma/
│ ├── schema.prisma # Database schema definition
│ ├── seed-lastone.ts # Database seeding script for AI companies
│ ├── seed-lastone.js # JavaScript version of seeding script
│ ├── lastone.csv # AI company data source
│ └── migrations/ # Database migration files
├── package.json # Project dependencies and scripts
└── tsconfig.json # TypeScript configuration
Development
Adding New Tools
To add a new MCP tool, modify src/server.ts and add a new tool definition:
server.tool(
"toolName",
"Tool description",
{
// Parameter schema using Zod
paramName: z.string().describe("Parameter description"),
},
{
// Tool metadata
title: "Tool Title",
readOnlyHint: false,
destructiveHint: false,
idempotentHint: false,
openWorldHint: true,
},
async (args) => {
// Tool implementation
return {
content: [{ type: "text", text: "Result" }],
};
}
);
Database Changes
- Modify
prisma/schema.prisma - Generate a new migration:
npx prisma migrate dev --name migration_name
- Update the Prisma client:
yarn prisma:generate
Seeding New Data
To seed the database with new AI company data:
- Update the CSV file (
prisma/lastone.csv) - Run the seed script:
yarn prisma:seed
Technologies Used
- MCP SDK:
@modelcontextprotocol/sdkfor building MCP servers - Prisma: Database ORM for PostgreSQL
- TypeScript: Type-safe JavaScript development
- Zod: Schema validation for tool parameters
- PostgreSQL: Relational database for data storage
License
ISC
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request