xsMCP0.1.0-beta.2

Tools

Enable LLMs to perform actions through your server

With xsSchema, the parameters here can support multiple libraries such as Zod, Valibot, ArkType, Effect Schema, Sury... at the same time.

server.addTool

import { createServer } from '@xsmcp/server-shared'
import { description, number, object, pipe } from 'valibot'

const server = createServer({ ...options })

server.addTool({
  description: 'Adds two numbers',
  execute: ({ a, b }) => [{ text: `The sum of ${a} and ${b} is ${a + b}.`, type: 'text' }],
  name: 'add',
  parameters: object({
    a: pipe(
      number(),
      description('First number'),
    ),
    b: pipe(
      number(),
      description('Second number'),
    ),
  }),
})

defineTool

import { createServer, defineTool } from '@xsmcp/server-shared'
import { description, number, object, pipe } from 'valibot'

const tool = defineTool({
  description: 'Adds two numbers',
  execute: ({ a, b }) => [{ text: `The sum of ${a} and ${b} is ${a + b}.`, type: 'text' }],
  name: 'add',
  parameters: object({
    a: pipe(
      number(),
      description('First number'),
    ),
    b: pipe(
      number(),
      description('Second number'),
    ),
  }),
})

const server = createServer({ ...options })

server.addTool(tool)