MCP Server

MCP Server

A Node In Layers package that simplifies creation of MCP (Model-Control-Protocol) servers with tools for defining models, adding CRUD operations, and interacting with clients.

Category
访问服务器

README

MCP Server - A Node In Layers Package for building MCP Servers

This library adds the ability to easily create MCP servers with Node In Layers.

It has a companion library called '@node-in-layers/mcp-client' which is used for creating MCP clients. These two libraries share the same functions for defining models and tools.

New Layer

This library adds a new layer mcp to the system. It should be placed after the express layer.

Usage

In order to use this library, you must make additions to your config, as well as create and export "mcp" layers from your apps/domains.

Config

you add this app/domain to your config file. You should do this before your apps which will add tools to the MCP server.

You then configure the mcp app/domain with the following:

const mcpConfig = {
  // (optional) The name of your MCP server.
  name: 'mcp',
  // (optional) The version of your MCP server.
  version: '1.0.0',
  // The server config from @l4t/mcp-ai/simple-server/types.js
  server: {
    connection: {
      type: 'http',
      host: 'localhost',
      port: 3000,
    },
  },
  logging: {
    // optional
    // If you want to change the default. Its 'info' by default.
    requestLogLevel: 'info',
    // If you want to change the default. Its 'info' by default.
    responseLogLevel: 'info',
  },
}

const config = {
  ['@node-in-layers/mcp-server']: mcpConfig,
}

Creating an MCP Layer

You can create an MCP layer by exporting a function from your app/domain that returns a layer.

// /src/yourDomain/mcp.ts
import { McpContext, McpNamespace } from '@node-in-layers/mcp-server'
import { Config } from '@node-in-layers/core'
import { YourFeaturesLayer } from './features.js'

const create = (context: McpContext<Config, YourFeaturesLayer>) => {
  // Adds your tool.
  context.mcp[McpNamespace].addTool({
    name: 'my-hello-world-tool',
    description: 'My Tool',
    execute: async (input: any) => {
      return 'Hello, world!'
    },
  })

  // Create a tool from your feature
  context.mcp[McpNamespace].addTool({
    name: 'my-hello-world-tool',
    description: 'My Tool',
    inputSchema: {
      type: 'object',
      properties: {
        name: {
          type: 'string',
        },
      },
      required: ['name'],
    },
    execute: (input: any) => {
      // You get an object, pass it back to your feature. Handles async for you.
      return context.features.yourDomain.yourFeature(input)
    },
  })

  return {}
}

export { create }

Adding Models

You can wrap your models with CRUDS functions and add them to the MCP server with the mcp layer. NOTE: In order for this to work your layer must have both a services and a features layer. (In addition to your models.) Node in layers will automatically create a cruds property for you with your models, and you can add them.

Here is an example of doing it one at a time. (Not generally recommended, but doable).

// /src/yourDomain/mcp.ts
import { McpContext, McpNamespace } from '@node-in-layers/mcp-server'
import { Config } from '@node-in-layers/core'
import { YourFeaturesLayer } from './features.js'

const create = (context: McpContext<Config, YourFeaturesLayer>) => {
  // Adds your models cruds through features.
  context.mcp[McpNamespace].addModelCruds(
    context.features.yourFeature.cruds.Cars
  )

  return {}
}

Here is a way that you can really cook with gas. (Highly recommended)

// /src/yourDomain/mcp.ts
import { McpContext, McpNamespace, mcpModels } from '@node-in-layers/mcp-server'
import { Config } from '@node-in-layers/core'
import { YourFeaturesLayer } from './features.js'

const create = (context: McpContext<Config, YourFeaturesLayer>) => {
  // This automatically adds ALL of your models from features.
  mcpModels('yourDomain')(context)

  return {}
}

Another way to organize adding models is from a centralized mcp domain. Put this as your very last domain after all your other domains have been loaded.

// /src/mcp/mcp.ts
import { McpContext, McpNamespace, mcpModels } from '@node-in-layers/mcp-server'
import { Config } from '@node-in-layers/core'

const create = (context: McpContext<Config>) => {
  // Add all your models for your whole system in one go.
  mcpModels('yourDomain')(context)
  mcpModels('yourDomain2')(context)
  mcpModels('yourDomain3')(context)
  mcpModels('yourDomain4')(context)

  return {}
}

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选