Skip to content

MCP Server #50

@cblanquera

Description

@cblanquera

Describe the feature you'd like to request

I want to have an MCP server script generated from idea files that provide tools for AI to safely interface with the database.

Describe the solution you'd like

The MCP standard that should be used is @modelcontextprotocol/sdk in combination with zod. see: https://github.com/cblanquera/mcp.md for example implementation.

NOTE: stackpress already generates zod schemas for models, fieldsets and column classes.

A simple MCP tool implementation that would be generated could look like:

import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import * as z from 'zod';
import ProfileSchema from 'stackpress-client/Profile/ProfileSchema';

const profile = new ProfileSchema();

export const schema = profile.shape;

export const info = {
  title: 'Search Profile,
  description: '',
  inputSchema: schema
};


export async function handler(server: Server, args: z.infer<typeof schema>) {
  //get zod params
  const params = profile.shape.parse(args);

  const results = await server.resolve('profile-create', params);

  return {
    content: [{ 
      type: 'text', 
      text: JSON.stringify(results, null, 2) 
    }]
  };
};

export function register(server: Server, mcp: McpServer, store: JsonlStore) {
  mcp.registerTool('profile_create', info, args => handler(server, args));
};

The basic idea is to map all the possible generated events to MCP tools, then transport via Streamable HTTP. You can configure the MCP tools in a config similar to how the api.endpoints config works.

{
  port: 17759,
  http: {
    cors: true,
    method: 'POST',
    endpoint: '/mcp'
  },
  tools: [
    {  name: 'profile_search', scopes: [ 'user' ] },
    {
      name: 'sample',
      description: 'This tools does sample',
      event: 'sample-search',
      params: {
        skip: { type: 'number', description: '' },
        take: { type: 'number', description: '' }
      },
      scopes: [ 'user' ]
    }
  ],
}

Where scopes are the scopes per application in the database.

Describe alternatives you've considered

There's another library called mcp-framework. Looks interesting, but I dont have enough experience to make a proper consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions