Skip to content

Commit

Permalink
feat: initial release of MCP tools with EchoTool implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianescutia committed Jan 8, 2025
0 parents commit 82d1a48
Show file tree
Hide file tree
Showing 10 changed files with 508 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
131 changes: 131 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.*

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
17 changes: 17 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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). 🚀
51 changes: 51 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
33 changes: 33 additions & 0 deletions src/EchoTool.ts
Original file line number Diff line number Diff line change
@@ -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<typeof EchoSchema>;
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<any> {
console.error("EchoTool executing with input:", input);
// nothing to do, just return the input message
return Promise.resolve({
content: [
{
type: "text",
text: `${input.message}`
}
]
});
}
}
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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);
});
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
Loading

0 comments on commit 82d1a48

Please # to comment.