From 82d1a485e55e349c98d40e96007889fdaf9f0e49 Mon Sep 17 00:00:00 2001 From: Adrian Escutia Soto Date: Tue, 7 Jan 2025 18:10:12 -0600 Subject: [PATCH] feat: initial release of MCP tools with EchoTool implementation --- .github/workflows/publish.yaml | 48 ++++++++++++ .gitignore | 131 +++++++++++++++++++++++++++++++++ LICENSE | 21 ++++++ README.md | 43 +++++++++++ RELEASE_NOTES.md | 17 +++++ package.json | 51 +++++++++++++ src/EchoTool.ts | 33 +++++++++ src/index.ts | 17 +++++ tsconfig.json | 16 ++++ yarn.lock | 131 +++++++++++++++++++++++++++++++++ 10 files changed, 508 insertions(+) create mode 100644 .github/workflows/publish.yaml create mode 100644 .gitignore create mode 100755 LICENSE create mode 100644 README.md create mode 100644 RELEASE_NOTES.md create mode 100644 package.json create mode 100644 src/EchoTool.ts create mode 100644 src/index.ts create mode 100644 tsconfig.json create mode 100644 yarn.lock diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..7199df8 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,48 @@ +name: Publish to npm + +on: + push: + branches: + - main + workflow_dispatch: # Allows manual triggering + +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '18' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Build project + run: npm run build + + - name: Configure Git + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + # - name: Bump version + # run: | + # npm version patch -m "chore: bump version to %s [skip ci]" + # git push + # git push --tags + + - name: Publish to npm + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5eb238 --- /dev/null +++ b/.gitignore @@ -0,0 +1,131 @@ +# Custom +build/ +*.ignoreme.* + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env* + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..f00c2d7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 La Rebelion Labs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5669f1 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Agent Template + +To keep it simple, at "La Rebelion" we have created server facade that can be used to simplify the creation of agents' tools. This repository contains the source code for the tools that can be registered with the server. + +For more details about the server's facade, visit the [GitHub repository](https://github.com/la-rebelion/mcp-server) or [npm package page](https://www.npmjs.com/package/@la-rebelion/mcp-server). + +We see tools as microservices and containers, must acomplish one task and do it well. This is the reason why we have created this pattern to help you to create your own tools. + +## Steps to Create a New Agent Tool + +```bash +mkdir -p my-agent/src +cd my-agent/ +yarn init -y +yarn add @modelcontextprotocol/sdk zod zod-to-json-schema @la-rebelion/mcp-server +yarn add -D @types/node typescript +``` + +Update the `package.json` file and create a `tsconfig.json` file. + +Implement the tool with the custom logic, and register it in the MCPServer, as simple as that. Check the EchoTool example in the `src` directory. + +Just register the tool with the server and start it. + +```typescript +// src/index.ts +// Create a new instance of the MCPServer +const myServer = new MCPServer('My MCP Server', '1.0.0'); + +async function main() { + // Register tools + myServer.registerTool("echo", new EchoTool()); + await myServer.run(); +} +``` + +![UML Diagram of the Agent Tool](https://github.com/la-rebelion/mcp-server/raw/refs/heads/main/mcp-server.png) + +## Support Us + +If you find this template useful, please consider supporting us by starring this repository, by contributing to the project or by becoming a sponsor. + +You can find more information on how to support us at [La Rebelion GitHub Sponsors](https://github.com/sponsors/la-rebelion). Also [buying us a coffee](https://buymeacoffee.com/larebelion), [PayPal](https://www.paypal.com/donate?hosted_button_id=7CV28AHGL9ZZY) are great ways to support us or purchasing ["La Rebelion" merch](https://go.rebelion.la/merch). \ No newline at end of file diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md new file mode 100644 index 0000000..51af787 --- /dev/null +++ b/RELEASE_NOTES.md @@ -0,0 +1,17 @@ +## Release Notes - Version 0.1.0 + +### Initial Release +- **EchoTool**: Example tool implementation that echoes input messages. +- **Schema Integration**: Utilizes `zod` for schema validation and `zod-to-json-schema` for schema conversion. + +### Documentation +- Updated README with usage instructions. + +### Miscellaneous +- Initial project setup with necessary dependencies and configurations. + +Go Rebels! ✊🏻 + +For more details, visit the [GitHub repository](https://github.com/la-rebelion/mcp-tools) or [npm package page](https://www.npmjs.com/package/@la-rebelion/mcp-tools). + +With ❤️ from [La Rebelion Labs](https://rebelion.la). 🚀 diff --git a/package.json b/package.json new file mode 100644 index 0000000..347accf --- /dev/null +++ b/package.json @@ -0,0 +1,51 @@ +{ + "name": "@la-rebelion/mcp-tools", + "version": "0.1.0", + "description": "MCP Tools implementation for La Rebelion Labs facade pattern", + "type": "module", + "author": { + "name": "La Rebelion Labs", + "url": "https://rebelion.la" + }, + "contributors": [ + { + "name": "Adrian Escutia", + "url": "https://escutia.me/adrian" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/la-rebelion/mcp-tools" + }, + "engines": { + "node": ">=18" + }, + "module": "src/index.ts", + "bin": { + "mcp-tools": "./build/index.js" + }, + "scripts": { + "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"", + "prepare": "npm run build", + "start": "node --disable-warning=ExperimentalWarning build/index.js", + "watch": "tsc --watch", + "inspector": "npx @modelcontextprotocol/inspector build/index.js" + }, + "files": [ + "build" + ], + "license": "MIT", + "dependencies": { + "@la-rebelion/mcp-server": "../mcp-server/", + "@modelcontextprotocol/sdk": "^1.0.4", + "zod": "^3.24.1", + "zod-to-json-schema": "^3.24.1" + }, + "devDependencies": { + "@types/node": "^22.10.3", + "typescript": "^5.7.2" + }, + "resolutions": { + "strip-ansi": "6.0.1" + } +} diff --git a/src/EchoTool.ts b/src/EchoTool.ts new file mode 100644 index 0000000..81ca751 --- /dev/null +++ b/src/EchoTool.ts @@ -0,0 +1,33 @@ +import { z } from "zod"; +import { zodToJsonSchema } from 'zod-to-json-schema'; +import {Tool} from "@la-rebelion/mcp-server"; + +const EchoSchema = z.object({ + message: z.string().describe("The message to echo"), +}); +type EchoInput = z.infer; +export class EchoTool extends Tool { + constructor() { + super(); + this.toolSchema = { + name: "echo", + description: "Echoes the input", + inputSchema: zodToJsonSchema(EchoSchema) + }; + } + init(): void { + console.error("EchoTool initialized"); + } + execute(input: EchoInput): Promise { + console.error("EchoTool executing with input:", input); + // nothing to do, just return the input message + return Promise.resolve({ + content: [ + { + type: "text", + text: `${input.message}` + } + ] + }); + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..67f4c4c --- /dev/null +++ b/src/index.ts @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +import {MCPServer} from "@la-rebelion/mcp-server"; +import { EchoTool } from "./EchoTool.js"; + +const myServer = new MCPServer('My MCP Server', '1.0.0'); + +async function main() { + // Register tools + myServer.registerTool("echo", new EchoTool()); + await myServer.run(); +} + +main().catch((error) => { + console.error("Server error:", error); + process.exit(1); +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..cefebf9 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "Node16", + "moduleResolution": "Node16", + "outDir": "./build", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "declaration": true + }, + "include": ["src/**/*", "index.ignoreme.d.ts-"], + "exclude": ["node_modules"] +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..30d170d --- /dev/null +++ b/yarn.lock @@ -0,0 +1,131 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@la-rebelion/mcp-server@../mcp-server/": + version "0.2.0" + dependencies: + "@modelcontextprotocol/sdk" "^1.1.0" + zod "^3.24.1" + zod-to-json-schema "^3.24.1" + +"@modelcontextprotocol/sdk@^1.0.4", "@modelcontextprotocol/sdk@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@modelcontextprotocol/sdk/-/sdk-1.1.0.tgz#9343ee9c53ac4138608572c2eb34db78752d8664" + integrity sha512-o5PIPz0vc1bJYXS0oLvRr8yUOzYtxEFL1rWP4aiO8qLslCksmbKhONy6CTpq0WPuIXUt2YuXoRtVA2EcLix3fw== + dependencies: + content-type "^1.0.5" + raw-body "^3.0.0" + zod "^3.23.8" + +"@types/node@^22.10.3": + version "22.10.5" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.5.tgz#95af89a3fb74a2bb41ef9927f206e6472026e48b" + integrity sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ== + dependencies: + undici-types "~6.20.0" + +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + +bytes@3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" + integrity sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg== + +content-type@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918" + integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA== + +depd@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" + integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw== + +http-errors@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3" + integrity sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ== + dependencies: + depd "2.0.0" + inherits "2.0.4" + setprototypeof "1.2.0" + statuses "2.0.1" + toidentifier "1.0.1" + +iconv-lite@0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" + integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== + dependencies: + safer-buffer ">= 2.1.2 < 3.0.0" + +inherits@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +raw-body@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-3.0.0.tgz#25b3476f07a51600619dae3fe82ddc28a36e5e0f" + integrity sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g== + dependencies: + bytes "3.1.2" + http-errors "2.0.0" + iconv-lite "0.6.3" + unpipe "1.0.0" + +"safer-buffer@>= 2.1.2 < 3.0.0": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +setprototypeof@1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" + integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw== + +statuses@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63" + integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ== + +strip-ansi@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +toidentifier@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" + integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== + +typescript@^5.7.2: + version "5.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.2.tgz#3169cf8c4c8a828cde53ba9ecb3d2b1d5dd67be6" + integrity sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg== + +undici-types@~6.20.0: + version "6.20.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433" + integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg== + +unpipe@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + integrity sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ== + +zod-to-json-schema@^3.24.1: + version "3.24.1" + resolved "https://registry.yarnpkg.com/zod-to-json-schema/-/zod-to-json-schema-3.24.1.tgz#f08c6725091aadabffa820ba8d50c7ab527f227a" + integrity sha512-3h08nf3Vw3Wl3PK+q3ow/lIil81IT2Oa7YpQyUUDsEWbXveMesdfK1xBd2RhCkynwZndAxixji/7SYJJowr62w== + +zod@^3.23.8, zod@^3.24.1: + version "3.24.1" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.1.tgz#27445c912738c8ad1e9de1bea0359fa44d9d35ee" + integrity sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==