my_first_mcp_server

vavanv/my_first_mcp_server

3.2

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.

Tools
2
Resources
0
Prompts
0

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 database
    • getReviews: Gets versions/reviews for a specific AI model by name
    • getChats: Retrieves all chat platforms and their information
    • getChatsByCompany: 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

  1. Clone the repository:
git clone <repository-url>
cd my_first_mcp_server
  1. Install dependencies:
yarn install
  1. Set up your environment variables by creating a .env file:
DATABASE_URL="postgresql://username:password@localhost:5432/your_database_name"
  1. Generate Prisma client:
yarn prisma:generate
  1. Run database migrations:
npx prisma migrate dev
  1. 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

  1. Modify prisma/schema.prisma
  2. Generate a new migration:
npx prisma migrate dev --name migration_name
  1. Update the Prisma client:
yarn prisma:generate

Seeding New Data

To seed the database with new AI company data:

  1. Update the CSV file (prisma/lastone.csv)
  2. Run the seed script:
yarn prisma:seed

Technologies Used

  • MCP SDK: @modelcontextprotocol/sdk for 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request