tool-server-template 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +14 -0
- package/LICENSE +13 -0
- package/README.md +611 -0
- package/TESTING.md +480 -0
- package/api/index.js +31 -0
- package/lib/build-site.d.ts +2 -0
- package/lib/build-site.d.ts.map +1 -0
- package/lib/build-site.js +42 -0
- package/lib/build-site.js.map +1 -0
- package/lib/copy-assets.d.ts +8 -0
- package/lib/copy-assets.d.ts.map +1 -0
- package/lib/copy-assets.js +62 -0
- package/lib/copy-assets.js.map +1 -0
- package/lib/interactions/index.d.ts +2 -0
- package/lib/interactions/index.d.ts.map +1 -0
- package/lib/interactions/index.js +10 -0
- package/lib/interactions/index.js.map +1 -0
- package/lib/interactions/summarize/icon.svg.d.ts +3 -0
- package/lib/interactions/summarize/icon.svg.d.ts.map +1 -0
- package/lib/interactions/summarize/icon.svg.js +10 -0
- package/lib/interactions/summarize/icon.svg.js.map +1 -0
- package/lib/interactions/summarize/index.d.ts +3 -0
- package/lib/interactions/summarize/index.d.ts.map +1 -0
- package/lib/interactions/summarize/index.js +14 -0
- package/lib/interactions/summarize/index.js.map +1 -0
- package/lib/interactions/summarize/text_summarizer/index.d.ts +53 -0
- package/lib/interactions/summarize/text_summarizer/index.d.ts.map +1 -0
- package/lib/interactions/summarize/text_summarizer/index.js +56 -0
- package/lib/interactions/summarize/text_summarizer/index.js.map +1 -0
- package/lib/interactions/summarize/text_summarizer/prompt.jst +31 -0
- package/lib/interactions/summarize/text_summarizer/prompt.jst.js +4 -0
- package/lib/interactions/summarize/text_summarizer/prompt.jst.js.map +1 -0
- package/lib/server-node.d.ts +2 -0
- package/lib/server-node.d.ts.map +1 -0
- package/lib/server-node.js +14 -0
- package/lib/server-node.js.map +1 -0
- package/lib/server.d.ts +3 -0
- package/lib/server.d.ts.map +1 -0
- package/lib/server.js +17 -0
- package/lib/server.js.map +1 -0
- package/lib/skills/code-review/SKILL.md +59 -0
- package/lib/skills/index.d.ts +4 -0
- package/lib/skills/index.d.ts.map +1 -0
- package/lib/skills/index.js +14 -0
- package/lib/skills/index.js.map +1 -0
- package/lib/tools/calculator/calculator.d.ts +23 -0
- package/lib/tools/calculator/calculator.d.ts.map +1 -0
- package/lib/tools/calculator/calculator.js +42 -0
- package/lib/tools/calculator/calculator.js.map +1 -0
- package/lib/tools/calculator/icon.svg.d.ts +3 -0
- package/lib/tools/calculator/icon.svg.d.ts.map +1 -0
- package/lib/tools/calculator/icon.svg.js +10 -0
- package/lib/tools/calculator/icon.svg.js.map +1 -0
- package/lib/tools/calculator/index.d.ts +3 -0
- package/lib/tools/calculator/index.d.ts.map +1 -0
- package/lib/tools/calculator/index.js +14 -0
- package/lib/tools/calculator/index.js.map +1 -0
- package/lib/tools/calculator/manifest.d.ts +16 -0
- package/lib/tools/calculator/manifest.d.ts.map +1 -0
- package/lib/tools/calculator/manifest.js +17 -0
- package/lib/tools/calculator/manifest.js.map +1 -0
- package/lib/tools/index.d.ts +2 -0
- package/lib/tools/index.d.ts.map +1 -0
- package/lib/tools/index.js +8 -0
- package/lib/tools/index.js.map +1 -0
- package/package.json +51 -0
- package/public/.gitkeep +1 -0
- package/rollup.config.bundle.js +60 -0
- package/rollup.config.js +99 -0
- package/src/build-site.ts +77 -0
- package/src/copy-assets.ts +104 -0
- package/src/interactions/index.ts +7 -0
- package/src/interactions/summarize/icon.svg.ts +7 -0
- package/src/interactions/summarize/index.ts +11 -0
- package/src/interactions/summarize/text_summarizer/index.ts +53 -0
- package/src/interactions/summarize/text_summarizer/prompt.jst +31 -0
- package/src/raw-imports.d.ts +4 -0
- package/src/server-node.ts +24 -0
- package/src/server.ts +22 -0
- package/src/skills/code-review/SKILL.md +59 -0
- package/src/skills/index.ts +12 -0
- package/src/tools/calculator/calculator.ts +60 -0
- package/src/tools/calculator/icon.svg.ts +7 -0
- package/src/tools/calculator/index.ts +11 -0
- package/src/tools/calculator/manifest.ts +16 -0
- package/src/tools/index.ts +5 -0
- package/template.config.json +27 -0
- package/tsconfig.json +25 -0
- package/vercel.json +29 -0
package/.env.example
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Environment Variables Template
|
|
2
|
+
# Copy this file to .env and fill in your values
|
|
3
|
+
|
|
4
|
+
# GitHub App Integration (optional)
|
|
5
|
+
# GITHUB_APP_ID=your-app-id
|
|
6
|
+
# GITHUB_APP_PRIVATE_KEY_FILE=path/to/private-key.pem
|
|
7
|
+
|
|
8
|
+
# Server Configuration
|
|
9
|
+
# PORT=5174
|
|
10
|
+
# NODE_ENV=development
|
|
11
|
+
|
|
12
|
+
# API Keys (if needed)
|
|
13
|
+
# API_KEY=your-api-key
|
|
14
|
+
# SECRET=your-secret
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2024 Composable Prompts
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
# Tool Server
|
|
2
|
+
|
|
3
|
+
A template for building custom tool servers that expose LLM tools, skills, interactions, and MCP providers. Built with [Hono](https://hono.dev/) for flexible deployment to Vercel Functions or Node.js HTTP servers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🛠️ **Tools**: Executable functions that can be invoked via API (e.g., calculator, API integrations)
|
|
8
|
+
- 🎯 **Skills**: AI capabilities defined as markdown prompts with optional helper scripts
|
|
9
|
+
- 🔄 **Interactions**: Multi-step agent workflows with templated prompts
|
|
10
|
+
- 🔌 **MCP Providers**: Model Context Protocol integrations (optional)
|
|
11
|
+
- 📄 **Auto-generated HTML**: Browse and explore resources with automatically generated pages
|
|
12
|
+
- 🚀 **Flexible Deployment**: Deploy to Vercel Functions, Cloud Run, Railway, or any Node.js host
|
|
13
|
+
- 📦 **Browser Bundles**: Standalone browser-ready bundles for client-side usage
|
|
14
|
+
- 🔧 **Simple Build**: Single Rollup config handles TypeScript, raw imports, and bundling
|
|
15
|
+
|
|
16
|
+
## Project Structure
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
tool-server-template/
|
|
20
|
+
├── src/
|
|
21
|
+
│ ├── tools/ # Tool collections
|
|
22
|
+
│ │ └── calculator/ # Example: calculator tool
|
|
23
|
+
│ │ ├── manifest.ts
|
|
24
|
+
│ │ ├── calculator.ts
|
|
25
|
+
│ │ ├── icon.svg.ts
|
|
26
|
+
│ │ └── index.ts
|
|
27
|
+
│ ├── skills/ # Skill collections
|
|
28
|
+
│ │ └── code-review/ # Example: code review skill
|
|
29
|
+
│ │ └── SKILL.md
|
|
30
|
+
│ ├── interactions/ # Interaction collections
|
|
31
|
+
│ │ └── summarize/ # Example: text summarization
|
|
32
|
+
│ │ └── text_summarizer/
|
|
33
|
+
│ │ ├── prompt.jst
|
|
34
|
+
│ │ └── index.ts
|
|
35
|
+
│ ├── server.ts # Hono server entry point
|
|
36
|
+
│ └── build-site.ts # Static HTML generator
|
|
37
|
+
├── api/
|
|
38
|
+
│ └── index.js # Vercel adapter
|
|
39
|
+
├── lib/ # Compiled code (TypeScript → JavaScript)
|
|
40
|
+
│ ├── server.js
|
|
41
|
+
│ ├── server-node.js
|
|
42
|
+
│ ├── tools/
|
|
43
|
+
│ └── ...
|
|
44
|
+
├── dist/ # Static HTML pages (public files)
|
|
45
|
+
│ ├── index.html
|
|
46
|
+
│ ├── tools/
|
|
47
|
+
│ ├── skills/
|
|
48
|
+
│ └── interactions/
|
|
49
|
+
├── public/ # Static assets
|
|
50
|
+
├── package.json
|
|
51
|
+
├── rollup.config.js # Unified build configuration (TypeScript + bundles)
|
|
52
|
+
├── vercel.json # Vercel deployment config
|
|
53
|
+
└── tsconfig.json
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Getting Started
|
|
57
|
+
|
|
58
|
+
### Prerequisites
|
|
59
|
+
|
|
60
|
+
- Node.js 18+
|
|
61
|
+
- npm or pnpm
|
|
62
|
+
|
|
63
|
+
### Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Install dependencies
|
|
67
|
+
npm install
|
|
68
|
+
# or
|
|
69
|
+
pnpm install
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Development
|
|
73
|
+
|
|
74
|
+
Start the development server with automatic rebuild and restart:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm run dev
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This will:
|
|
81
|
+
1. **Initial build** - Compiles TypeScript and generates HTML pages
|
|
82
|
+
2. **Rollup watch mode** - Rebuilds TypeScript on file changes
|
|
83
|
+
3. **Node.js with --watch** - Restarts server when lib/ changes
|
|
84
|
+
|
|
85
|
+
The server will be available at:
|
|
86
|
+
- API: http://localhost:3000/api
|
|
87
|
+
- Web UI: http://localhost:3000
|
|
88
|
+
|
|
89
|
+
To use a different port:
|
|
90
|
+
```bash
|
|
91
|
+
PORT=8080 npm run dev
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Manual control (advanced):**
|
|
95
|
+
```bash
|
|
96
|
+
# Terminal 1: Build on changes
|
|
97
|
+
npm run build:watch
|
|
98
|
+
|
|
99
|
+
# Terminal 2: Server with auto-restart
|
|
100
|
+
npm run start:watch
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Building
|
|
104
|
+
|
|
105
|
+
Build the project for production:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm run build
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This will:
|
|
112
|
+
1. **Rollup**: Compile TypeScript to JavaScript in `lib/` (ESM with preserveModules)
|
|
113
|
+
2. **Copy assets**: Copy skill assets (.md, .py files) to `lib/`
|
|
114
|
+
3. **Generate HTML**: Create static HTML pages in `dist/`
|
|
115
|
+
4. **Rollup**: Create browser bundles in `dist/libs/`
|
|
116
|
+
|
|
117
|
+
The build uses a single **rollup.config.js** that handles:
|
|
118
|
+
- TypeScript compilation with `@rollup/plugin-typescript` → `lib/`
|
|
119
|
+
- `?raw` imports for template files (via custom rawPlugin)
|
|
120
|
+
- Browser bundles with tree-shaking and minification → `dist/libs/`
|
|
121
|
+
|
|
122
|
+
**Output structure:**
|
|
123
|
+
- `lib/` = Compiled code (what you run)
|
|
124
|
+
- `dist/` = Static HTML + browser bundles (what you serve)
|
|
125
|
+
|
|
126
|
+
## Creating Resources
|
|
127
|
+
|
|
128
|
+
### 1. Creating a Tool
|
|
129
|
+
|
|
130
|
+
Tools are executable functions that can be invoked via API.
|
|
131
|
+
|
|
132
|
+
**Structure:**
|
|
133
|
+
```
|
|
134
|
+
src/tools/my-tool/
|
|
135
|
+
├── manifest.ts # Tool metadata and schema
|
|
136
|
+
├── my-tool.ts # Implementation
|
|
137
|
+
├── icon.svg.ts # SVG icon
|
|
138
|
+
└── index.ts # Collection export
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Example: manifest.ts**
|
|
142
|
+
```typescript
|
|
143
|
+
import { ToolDefinition } from "@vertesia/tools-sdk";
|
|
144
|
+
|
|
145
|
+
export default {
|
|
146
|
+
name: "my-tool",
|
|
147
|
+
description: "Description of what this tool does",
|
|
148
|
+
input_schema: {
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: {
|
|
151
|
+
param1: {
|
|
152
|
+
type: "string",
|
|
153
|
+
description: "First parameter"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
required: ["param1"]
|
|
157
|
+
}
|
|
158
|
+
} satisfies ToolDefinition;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Example: my-tool.ts**
|
|
162
|
+
```typescript
|
|
163
|
+
import { Tool, ToolExecutionContext } from "@vertesia/tools-sdk";
|
|
164
|
+
import manifest from "./manifest.js";
|
|
165
|
+
|
|
166
|
+
interface MyToolParams {
|
|
167
|
+
param1: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function execute(
|
|
171
|
+
params: MyToolParams,
|
|
172
|
+
context: ToolExecutionContext
|
|
173
|
+
): Promise<string> {
|
|
174
|
+
// Tool implementation
|
|
175
|
+
return `Processed: ${params.param1}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const MyTool = {
|
|
179
|
+
...manifest,
|
|
180
|
+
run: execute
|
|
181
|
+
} satisfies Tool<MyToolParams>;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Example: index.ts**
|
|
185
|
+
```typescript
|
|
186
|
+
import { ToolCollection } from "@vertesia/tools-sdk";
|
|
187
|
+
import { MyTool } from "./my-tool.js";
|
|
188
|
+
import icon from "./icon.svg.js";
|
|
189
|
+
|
|
190
|
+
export const MyTools = new ToolCollection({
|
|
191
|
+
name: "my-tool",
|
|
192
|
+
title: "My Tools",
|
|
193
|
+
description: "Description of the tool collection",
|
|
194
|
+
icon,
|
|
195
|
+
tools: [MyTool]
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Register the collection:**
|
|
200
|
+
|
|
201
|
+
Add to `src/tools/index.ts`:
|
|
202
|
+
```typescript
|
|
203
|
+
import { MyTools } from "./my-tool/index.js";
|
|
204
|
+
|
|
205
|
+
export const tools = [
|
|
206
|
+
MyTools,
|
|
207
|
+
// ... other collections
|
|
208
|
+
];
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 2. Creating a Skill
|
|
212
|
+
|
|
213
|
+
Skills are AI capabilities defined as markdown prompts.
|
|
214
|
+
|
|
215
|
+
**Structure:**
|
|
216
|
+
```
|
|
217
|
+
src/skills/my-skill/
|
|
218
|
+
├── SKILL.md # Skill definition
|
|
219
|
+
└── helper.py # Optional helper script
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Example: SKILL.md**
|
|
223
|
+
```markdown
|
|
224
|
+
---
|
|
225
|
+
name: my-skill
|
|
226
|
+
title: My Skill
|
|
227
|
+
keywords: keyword1, keyword2, keyword3
|
|
228
|
+
tools: tool1, tool2
|
|
229
|
+
packages: package1==1.0.0
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
# My Skill
|
|
233
|
+
|
|
234
|
+
You are an AI assistant with expertise in [domain].
|
|
235
|
+
|
|
236
|
+
## Instructions
|
|
237
|
+
|
|
238
|
+
1. First instruction
|
|
239
|
+
2. Second instruction
|
|
240
|
+
3. Third instruction
|
|
241
|
+
|
|
242
|
+
## Guidelines
|
|
243
|
+
|
|
244
|
+
- Guideline 1
|
|
245
|
+
- Guideline 2
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Register the collection:**
|
|
249
|
+
|
|
250
|
+
Create `src/skills/my-skill/index.ts`:
|
|
251
|
+
```typescript
|
|
252
|
+
import { SkillCollection, loadSkillsFromDirectory } from "@vertesia/tools-sdk";
|
|
253
|
+
|
|
254
|
+
export const MySkills = new SkillCollection({
|
|
255
|
+
name: "my-skill",
|
|
256
|
+
title: "My Skills",
|
|
257
|
+
description: "Description of the skill collection",
|
|
258
|
+
skills: loadSkillsFromDirectory(new URL(".", import.meta.url).pathname)
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Add to `src/skills/index.ts`:
|
|
263
|
+
```typescript
|
|
264
|
+
import { MySkills } from "./my-skill/index.js";
|
|
265
|
+
|
|
266
|
+
export const skills = [
|
|
267
|
+
MySkills,
|
|
268
|
+
// ... other collections
|
|
269
|
+
];
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### 3. Creating an Interaction
|
|
273
|
+
|
|
274
|
+
Interactions are multi-step workflows with templated prompts.
|
|
275
|
+
|
|
276
|
+
**Structure:**
|
|
277
|
+
```
|
|
278
|
+
src/interactions/my-interaction/
|
|
279
|
+
└── my_workflow/
|
|
280
|
+
├── prompt.jst # JavaScript template string
|
|
281
|
+
└── index.ts # Interaction spec
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Example: prompt.jst**
|
|
285
|
+
```javascript
|
|
286
|
+
return `
|
|
287
|
+
# Task: ${taskName}
|
|
288
|
+
|
|
289
|
+
## Parameters
|
|
290
|
+
- **Input**: ${input}
|
|
291
|
+
- **Options**: ${JSON.stringify(options)}
|
|
292
|
+
|
|
293
|
+
## Instructions
|
|
294
|
+
|
|
295
|
+
Please process the following according to the parameters above.
|
|
296
|
+
|
|
297
|
+
${additionalInstructions || 'No additional instructions.'}
|
|
298
|
+
`;
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**Example: index.ts**
|
|
302
|
+
```typescript
|
|
303
|
+
import { PromptRole } from "@llumiverse/common";
|
|
304
|
+
import { InteractionSpec, TemplateType } from "@vertesia/common";
|
|
305
|
+
import PROMPT_CONTENT from "./prompt.jst?raw";
|
|
306
|
+
|
|
307
|
+
export default {
|
|
308
|
+
name: "my_workflow",
|
|
309
|
+
title: "My Workflow",
|
|
310
|
+
description: "Description of what this interaction does",
|
|
311
|
+
result_schema: {
|
|
312
|
+
type: "object",
|
|
313
|
+
properties: {
|
|
314
|
+
result: {
|
|
315
|
+
type: "string",
|
|
316
|
+
description: "The workflow result"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
required: ["result"]
|
|
320
|
+
},
|
|
321
|
+
prompts: [{
|
|
322
|
+
role: PromptRole.user,
|
|
323
|
+
content: PROMPT_CONTENT,
|
|
324
|
+
content_type: TemplateType.jst,
|
|
325
|
+
schema: {
|
|
326
|
+
type: "object",
|
|
327
|
+
properties: {
|
|
328
|
+
taskName: { type: "string" },
|
|
329
|
+
input: { type: "string" },
|
|
330
|
+
options: { type: "object" },
|
|
331
|
+
additionalInstructions: { type: "string" }
|
|
332
|
+
},
|
|
333
|
+
required: ["taskName", "input"]
|
|
334
|
+
}
|
|
335
|
+
}],
|
|
336
|
+
tags: ["tag1", "tag2"]
|
|
337
|
+
} satisfies InteractionSpec;
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Register the collection:**
|
|
341
|
+
|
|
342
|
+
Create `src/interactions/my-interaction/index.ts`:
|
|
343
|
+
```typescript
|
|
344
|
+
import { InteractionCollection } from "@vertesia/tools-sdk";
|
|
345
|
+
import myWorkflow from "./my_workflow/index.js";
|
|
346
|
+
import icon from "./icon.svg.js";
|
|
347
|
+
|
|
348
|
+
export const MyInteractions = new InteractionCollection({
|
|
349
|
+
name: "my-interaction",
|
|
350
|
+
title: "My Interactions",
|
|
351
|
+
description: "Description of the interaction collection",
|
|
352
|
+
icon,
|
|
353
|
+
interactions: [myWorkflow]
|
|
354
|
+
});
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Add to `src/interactions/index.ts`:
|
|
358
|
+
```typescript
|
|
359
|
+
import { MyInteractions } from "./my-interaction/index.js";
|
|
360
|
+
|
|
361
|
+
export async function loadInteractions() {
|
|
362
|
+
return [
|
|
363
|
+
MyInteractions,
|
|
364
|
+
// ... other collections
|
|
365
|
+
];
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## API Reference
|
|
370
|
+
|
|
371
|
+
### Endpoints
|
|
372
|
+
|
|
373
|
+
#### `GET /api`
|
|
374
|
+
Returns descriptions of all available tools, skills, and interactions.
|
|
375
|
+
|
|
376
|
+
**Response:**
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"tools": [...],
|
|
380
|
+
"skills": [...],
|
|
381
|
+
"interactions": [...]
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### `POST /api`
|
|
386
|
+
Executes a tool with the provided payload.
|
|
387
|
+
|
|
388
|
+
**Request Body:**
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"tool_name": "calculator",
|
|
392
|
+
"tool_input": {
|
|
393
|
+
"expression": "2 + 2"
|
|
394
|
+
},
|
|
395
|
+
"context": {
|
|
396
|
+
"serverUrl": "http://localhost:5174",
|
|
397
|
+
"storeUrl": "http://store.example.com",
|
|
398
|
+
"apikey": "your-api-key"
|
|
399
|
+
},
|
|
400
|
+
"vars": {}
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**Response:**
|
|
405
|
+
```json
|
|
406
|
+
{
|
|
407
|
+
"is_error": false,
|
|
408
|
+
"content": "Result: 2 + 2 = 4"
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Deployment
|
|
413
|
+
|
|
414
|
+
The template supports **two deployment modes**:
|
|
415
|
+
|
|
416
|
+
### 1. Vercel Functions (Serverless)
|
|
417
|
+
|
|
418
|
+
Best for: Auto-scaling, zero-config deployment
|
|
419
|
+
|
|
420
|
+
```bash
|
|
421
|
+
# Install Vercel CLI
|
|
422
|
+
npm i -g vercel
|
|
423
|
+
|
|
424
|
+
# Deploy
|
|
425
|
+
vercel
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
The `api/index.js` adapter automatically converts your Hono server to Vercel Functions format.
|
|
429
|
+
|
|
430
|
+
### 2. Node.js HTTP Server
|
|
431
|
+
|
|
432
|
+
Best for: Cloud Run, Railway, Fly.io, Docker, VPS
|
|
433
|
+
|
|
434
|
+
The template includes `src/server-node.ts` which creates a standalone HTTP server.
|
|
435
|
+
|
|
436
|
+
**Deploy to Cloud Run:**
|
|
437
|
+
```bash
|
|
438
|
+
gcloud run deploy tool-server \
|
|
439
|
+
--source . \
|
|
440
|
+
--platform managed \
|
|
441
|
+
--region us-central1
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
**Deploy to Railway:**
|
|
445
|
+
1. Connect your repo
|
|
446
|
+
2. Railway auto-detects Node.js
|
|
447
|
+
3. Uses `npm start` automatically
|
|
448
|
+
|
|
449
|
+
**Deploy to Docker:**
|
|
450
|
+
```dockerfile
|
|
451
|
+
FROM node:18-alpine
|
|
452
|
+
WORKDIR /app
|
|
453
|
+
COPY package*.json ./
|
|
454
|
+
RUN npm install --production
|
|
455
|
+
COPY . .
|
|
456
|
+
RUN npm run build
|
|
457
|
+
EXPOSE 3000
|
|
458
|
+
CMD ["npm", "start"]
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
**Deploy to VPS:**
|
|
462
|
+
```bash
|
|
463
|
+
# On your server
|
|
464
|
+
git clone <your-repo>
|
|
465
|
+
cd tool-server-template
|
|
466
|
+
npm install
|
|
467
|
+
npm run build
|
|
468
|
+
npm start
|
|
469
|
+
|
|
470
|
+
# Or use PM2 for process management
|
|
471
|
+
npm i -g pm2
|
|
472
|
+
pm2 start lib/server-node.js --name tool-server
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Other Platforms
|
|
476
|
+
|
|
477
|
+
Hono's flexibility allows deployment to:
|
|
478
|
+
- Cloudflare Workers
|
|
479
|
+
- Deno Deploy
|
|
480
|
+
- AWS Lambda (with adapter)
|
|
481
|
+
- Bun
|
|
482
|
+
- Azure Functions
|
|
483
|
+
|
|
484
|
+
See [Hono documentation](https://hono.dev/getting-started/basic) for platform-specific guides.
|
|
485
|
+
|
|
486
|
+
## Configuration
|
|
487
|
+
|
|
488
|
+
### Customization
|
|
489
|
+
|
|
490
|
+
Edit `src/server.ts` to customize:
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
const server = createToolServer({
|
|
494
|
+
title: 'Your Server Name',
|
|
495
|
+
description: 'Your server description',
|
|
496
|
+
prefix: '/api',
|
|
497
|
+
tools,
|
|
498
|
+
interactions,
|
|
499
|
+
skills,
|
|
500
|
+
mcpProviders: [] // Add MCP providers here
|
|
501
|
+
});
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### Environment Variables
|
|
505
|
+
|
|
506
|
+
For GitHub integration or other sensitive config, use environment variables:
|
|
507
|
+
|
|
508
|
+
1. Create `.env` file:
|
|
509
|
+
```bash
|
|
510
|
+
GITHUB_APP_ID=your-app-id
|
|
511
|
+
GITHUB_APP_PRIVATE_KEY_FILE=path/to/key.pem
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
2. Access in code:
|
|
515
|
+
```typescript
|
|
516
|
+
const githubAppId = process.env.GITHUB_APP_ID;
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
## Browser Bundles
|
|
520
|
+
|
|
521
|
+
After building, browser-ready bundles are available at:
|
|
522
|
+
```
|
|
523
|
+
dist/libs/tool-server-{collection-name}.js
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
Use them in the browser:
|
|
527
|
+
```html
|
|
528
|
+
<script type="module">
|
|
529
|
+
import { CalculatorTools } from './libs/tool-server-calculator.js';
|
|
530
|
+
// Use the tools
|
|
531
|
+
</script>
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
## Debugging
|
|
535
|
+
|
|
536
|
+
This template includes full VSCode debugging support with breakpoints, watch expressions, and call stack inspection.
|
|
537
|
+
|
|
538
|
+
**Quick start:**
|
|
539
|
+
1. Press **F5** in VSCode
|
|
540
|
+
2. Select "Debug Server"
|
|
541
|
+
3. Set breakpoints in your TypeScript files
|
|
542
|
+
4. Make API requests to trigger breakpoints
|
|
543
|
+
|
|
544
|
+
For complete debugging workflows, configurations, and troubleshooting, see **[.vscode/README.md](.vscode/README.md)**.
|
|
545
|
+
|
|
546
|
+
## Development Tips
|
|
547
|
+
|
|
548
|
+
1. **Watch Mode**: `npm run dev` automatically rebuilds and restarts on file changes
|
|
549
|
+
2. **Type Safety**: Use `satisfies` to ensure type correctness while preserving inference
|
|
550
|
+
3. **Raw Imports**: Use `import content from './file.jst?raw'` for large template strings
|
|
551
|
+
4. **Debugging**: See [.vscode/README.md](.vscode/README.md) for VSCode debugging setup
|
|
552
|
+
5. **Testing Tools**: Use `POST /api` with curl or Postman to test tools
|
|
553
|
+
|
|
554
|
+
### Testing with curl
|
|
555
|
+
|
|
556
|
+
**Test a tool:**
|
|
557
|
+
```bash
|
|
558
|
+
curl -H "Authorization: Bearer {{VERTESIA_JWT}}" \
|
|
559
|
+
-H "Content-Type: application/json" \
|
|
560
|
+
-X POST "http://localhost:3000/api/tools/calculator" \
|
|
561
|
+
-d '{
|
|
562
|
+
"tool_use": {
|
|
563
|
+
"id": "run1",
|
|
564
|
+
"tool_name": "calculator",
|
|
565
|
+
"tool_input": {"expression": "10 * 5"}
|
|
566
|
+
}
|
|
567
|
+
}'
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
**Get interaction details:**
|
|
571
|
+
```bash
|
|
572
|
+
curl -H "Authorization: Bearer {{VERTESIA_JWT}}" \
|
|
573
|
+
"http://localhost:3000/api/interactions/summarize/text_summarizer"
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
**Get skill details:**
|
|
577
|
+
```bash
|
|
578
|
+
curl -H "Authorization: Bearer {{VERTESIA_JWT}}" \
|
|
579
|
+
"http://localhost:3000/api/skills/code-review/skill_code-review"
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
Replace `{{VERTESIA_JWT}}` with a valid Vertesia JWT token.
|
|
583
|
+
|
|
584
|
+
## Troubleshooting
|
|
585
|
+
|
|
586
|
+
### Build fails with module errors
|
|
587
|
+
- Ensure all imports use `.js` extensions (ESM requirement)
|
|
588
|
+
- Check that `tsconfig.json` has `"module": "ES2022"`
|
|
589
|
+
- Verify `@rollup/plugin-typescript` is installed
|
|
590
|
+
|
|
591
|
+
### Dev server not starting
|
|
592
|
+
- Make sure `concurrently` is installed
|
|
593
|
+
- Check that dependencies are installed (`npm install`)
|
|
594
|
+
- If still having issues, try `npm run build` manually first
|
|
595
|
+
|
|
596
|
+
### Tool execution errors
|
|
597
|
+
- Check tool implementation returns a string
|
|
598
|
+
- Verify input_schema matches the parameters
|
|
599
|
+
- Check console for detailed error messages
|
|
600
|
+
|
|
601
|
+
## License
|
|
602
|
+
|
|
603
|
+
MIT
|
|
604
|
+
|
|
605
|
+
## Contributing
|
|
606
|
+
|
|
607
|
+
Contributions are welcome! Please feel free to submit issues or pull requests.
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
Built with ❤️ using [Hono](https://hono.dev/) and [@vertesia/tools-sdk](https://github.com/vertesia/tools-sdk)
|