@musashishao/agent-kit 1.2.2

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.
Files changed (236) hide show
  1. package/.agent/agents/backend-specialist.md +263 -0
  2. package/.agent/agents/database-architect.md +226 -0
  3. package/.agent/agents/debugger.md +225 -0
  4. package/.agent/agents/devops-engineer.md +242 -0
  5. package/.agent/agents/documentation-writer.md +104 -0
  6. package/.agent/agents/explorer-agent.md +73 -0
  7. package/.agent/agents/frontend-specialist.md +556 -0
  8. package/.agent/agents/game-developer.md +162 -0
  9. package/.agent/agents/mobile-developer.md +377 -0
  10. package/.agent/agents/orchestrator.md +416 -0
  11. package/.agent/agents/penetration-tester.md +188 -0
  12. package/.agent/agents/performance-optimizer.md +187 -0
  13. package/.agent/agents/project-planner.md +403 -0
  14. package/.agent/agents/security-auditor.md +170 -0
  15. package/.agent/agents/seo-specialist.md +111 -0
  16. package/.agent/agents/test-engineer.md +158 -0
  17. package/.agent/mcp/README.md +69 -0
  18. package/.agent/mcp/config/mcp-config.json +62 -0
  19. package/.agent/mcp/config/registry.json +54 -0
  20. package/.agent/mcp/servers/agent-kit-core/package.json +28 -0
  21. package/.agent/mcp/servers/agent-kit-core/src/index.ts +455 -0
  22. package/.agent/mcp/servers/agent-kit-core/tsconfig.json +16 -0
  23. package/.agent/mcp/servers/agent-kit-fs/package.json +25 -0
  24. package/.agent/mcp/servers/agent-kit-fs/src/index.ts +399 -0
  25. package/.agent/mcp/servers/agent-kit-fs/tsconfig.json +16 -0
  26. package/.agent/mcp/servers/agent-kit-git/package.json +24 -0
  27. package/.agent/mcp/servers/agent-kit-git/src/index.ts +283 -0
  28. package/.agent/mcp/servers/agent-kit-git/tsconfig.json +16 -0
  29. package/.agent/mcp/templates/README.md +49 -0
  30. package/.agent/mcp/templates/api/README.md.template +45 -0
  31. package/.agent/mcp/templates/api/src/index.ts.template +185 -0
  32. package/.agent/mcp/templates/base-package.json.template +27 -0
  33. package/.agent/mcp/templates/base-tsconfig.json +21 -0
  34. package/.agent/mcp/templates/custom/src/index.ts.template +133 -0
  35. package/.agent/mcp/templates/database/src/index.ts.template +273 -0
  36. package/.agent/mcp/templates/web-scraper/src/index.ts.template +239 -0
  37. package/.agent/rules/CODEX.md +250 -0
  38. package/.agent/rules/GEMINI.md +251 -0
  39. package/.agent/skills/api-patterns/SKILL.md +81 -0
  40. package/.agent/skills/api-patterns/api-style.md +42 -0
  41. package/.agent/skills/api-patterns/auth.md +24 -0
  42. package/.agent/skills/api-patterns/documentation.md +26 -0
  43. package/.agent/skills/api-patterns/graphql.md +41 -0
  44. package/.agent/skills/api-patterns/rate-limiting.md +31 -0
  45. package/.agent/skills/api-patterns/response.md +37 -0
  46. package/.agent/skills/api-patterns/rest.md +40 -0
  47. package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
  48. package/.agent/skills/api-patterns/security-testing.md +122 -0
  49. package/.agent/skills/api-patterns/trpc.md +41 -0
  50. package/.agent/skills/api-patterns/versioning.md +22 -0
  51. package/.agent/skills/app-builder/SKILL.md +75 -0
  52. package/.agent/skills/app-builder/agent-coordination.md +71 -0
  53. package/.agent/skills/app-builder/feature-building.md +53 -0
  54. package/.agent/skills/app-builder/project-detection.md +34 -0
  55. package/.agent/skills/app-builder/scaffolding.md +118 -0
  56. package/.agent/skills/app-builder/tech-stack.md +40 -0
  57. package/.agent/skills/app-builder/templates/SKILL.md +39 -0
  58. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  59. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  60. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  61. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  62. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
  63. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  64. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  65. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +82 -0
  66. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +100 -0
  67. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +106 -0
  68. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +101 -0
  69. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  70. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +93 -0
  71. package/.agent/skills/architecture/SKILL.md +55 -0
  72. package/.agent/skills/architecture/context-discovery.md +43 -0
  73. package/.agent/skills/architecture/examples.md +94 -0
  74. package/.agent/skills/architecture/pattern-selection.md +68 -0
  75. package/.agent/skills/architecture/patterns-reference.md +50 -0
  76. package/.agent/skills/architecture/trade-off-analysis.md +77 -0
  77. package/.agent/skills/bash-linux/SKILL.md +199 -0
  78. package/.agent/skills/behavioral-modes/SKILL.md +242 -0
  79. package/.agent/skills/brainstorming/SKILL.md +163 -0
  80. package/.agent/skills/brainstorming/dynamic-questioning.md +350 -0
  81. package/.agent/skills/clean-code/SKILL.md +201 -0
  82. package/.agent/skills/code-review-checklist/SKILL.md +109 -0
  83. package/.agent/skills/context-engineering/SKILL.md +74 -0
  84. package/.agent/skills/context-engineering/examples/advanced_code_request.md +73 -0
  85. package/.agent/skills/context-engineering/scripts/quality_validator.py +294 -0
  86. package/.agent/skills/context-engineering/scripts/repo_mapper.py +27 -0
  87. package/.agent/skills/context-engineering/scripts/skill_checker.py +194 -0
  88. package/.agent/skills/context-engineering/scripts/token_counter.py +65 -0
  89. package/.agent/skills/context-engineering/strategies/context-caching.md +50 -0
  90. package/.agent/skills/context-engineering/strategies/few-shot-examples.md +56 -0
  91. package/.agent/skills/context-engineering/strategies/skeleton-code.md +59 -0
  92. package/.agent/skills/context-engineering/strategies/xml-framing.md +57 -0
  93. package/.agent/skills/database-design/SKILL.md +52 -0
  94. package/.agent/skills/database-design/database-selection.md +43 -0
  95. package/.agent/skills/database-design/indexing.md +39 -0
  96. package/.agent/skills/database-design/migrations.md +48 -0
  97. package/.agent/skills/database-design/optimization.md +36 -0
  98. package/.agent/skills/database-design/orm-selection.md +30 -0
  99. package/.agent/skills/database-design/schema-design.md +56 -0
  100. package/.agent/skills/database-design/scripts/schema_validator.py +172 -0
  101. package/.agent/skills/deployment-procedures/SKILL.md +241 -0
  102. package/.agent/skills/doc.md +177 -0
  103. package/.agent/skills/docker-expert/SKILL.md +409 -0
  104. package/.agent/skills/documentation-templates/SKILL.md +194 -0
  105. package/.agent/skills/frontend-design/SKILL.md +396 -0
  106. package/.agent/skills/frontend-design/animation-guide.md +331 -0
  107. package/.agent/skills/frontend-design/color-system.md +311 -0
  108. package/.agent/skills/frontend-design/decision-trees.md +418 -0
  109. package/.agent/skills/frontend-design/motion-graphics.md +306 -0
  110. package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  111. package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
  112. package/.agent/skills/frontend-design/typography-system.md +345 -0
  113. package/.agent/skills/frontend-design/ux-psychology.md +541 -0
  114. package/.agent/skills/frontend-design/visual-effects.md +383 -0
  115. package/.agent/skills/game-development/2d-games/SKILL.md +119 -0
  116. package/.agent/skills/game-development/3d-games/SKILL.md +135 -0
  117. package/.agent/skills/game-development/SKILL.md +167 -0
  118. package/.agent/skills/game-development/game-art/SKILL.md +185 -0
  119. package/.agent/skills/game-development/game-audio/SKILL.md +190 -0
  120. package/.agent/skills/game-development/game-design/SKILL.md +129 -0
  121. package/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
  122. package/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
  123. package/.agent/skills/game-development/pc-games/SKILL.md +144 -0
  124. package/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
  125. package/.agent/skills/game-development/web-games/SKILL.md +150 -0
  126. package/.agent/skills/geo-fundamentals/SKILL.md +156 -0
  127. package/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
  128. package/.agent/skills/i18n-localization/SKILL.md +154 -0
  129. package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
  130. package/.agent/skills/lint-and-validate/SKILL.md +45 -0
  131. package/.agent/skills/lint-and-validate/scripts/lint_runner.py +172 -0
  132. package/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
  133. package/.agent/skills/mcp-builder/SKILL.md +662 -0
  134. package/.agent/skills/mcp-builder/python-template.md +522 -0
  135. package/.agent/skills/mcp-builder/tool-patterns.md +642 -0
  136. package/.agent/skills/mcp-builder/typescript-template.md +361 -0
  137. package/.agent/skills/mobile-design/SKILL.md +394 -0
  138. package/.agent/skills/mobile-design/decision-trees.md +516 -0
  139. package/.agent/skills/mobile-design/mobile-backend.md +491 -0
  140. package/.agent/skills/mobile-design/mobile-color-system.md +420 -0
  141. package/.agent/skills/mobile-design/mobile-debugging.md +122 -0
  142. package/.agent/skills/mobile-design/mobile-design-thinking.md +357 -0
  143. package/.agent/skills/mobile-design/mobile-navigation.md +458 -0
  144. package/.agent/skills/mobile-design/mobile-performance.md +767 -0
  145. package/.agent/skills/mobile-design/mobile-testing.md +356 -0
  146. package/.agent/skills/mobile-design/mobile-typography.md +433 -0
  147. package/.agent/skills/mobile-design/platform-android.md +666 -0
  148. package/.agent/skills/mobile-design/platform-ios.md +561 -0
  149. package/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
  150. package/.agent/skills/mobile-design/touch-psychology.md +537 -0
  151. package/.agent/skills/nestjs-expert/SKILL.md +552 -0
  152. package/.agent/skills/nextjs-best-practices/SKILL.md +203 -0
  153. package/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
  154. package/.agent/skills/parallel-agents/SKILL.md +175 -0
  155. package/.agent/skills/performance-profiling/SKILL.md +143 -0
  156. package/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
  157. package/.agent/skills/plan-writing/SKILL.md +152 -0
  158. package/.agent/skills/powershell-windows/SKILL.md +167 -0
  159. package/.agent/skills/prisma-expert/SKILL.md +355 -0
  160. package/.agent/skills/problem-solving/SKILL.md +556 -0
  161. package/.agent/skills/problem-solving/collision-zone-thinking.md +285 -0
  162. package/.agent/skills/problem-solving/inversion-exercise.md +205 -0
  163. package/.agent/skills/problem-solving/meta-pattern-recognition.md +313 -0
  164. package/.agent/skills/problem-solving/scale-game.md +300 -0
  165. package/.agent/skills/problem-solving/simplification-cascades.md +321 -0
  166. package/.agent/skills/problem-solving/when-stuck.md +146 -0
  167. package/.agent/skills/python-patterns/SKILL.md +441 -0
  168. package/.agent/skills/react-patterns/SKILL.md +198 -0
  169. package/.agent/skills/red-team-tactics/SKILL.md +199 -0
  170. package/.agent/skills/seo-fundamentals/SKILL.md +129 -0
  171. package/.agent/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
  172. package/.agent/skills/server-management/SKILL.md +161 -0
  173. package/.agent/skills/systematic-debugging/SKILL.md +109 -0
  174. package/.agent/skills/tailwind-patterns/SKILL.md +269 -0
  175. package/.agent/skills/tdd-workflow/SKILL.md +149 -0
  176. package/.agent/skills/testing-patterns/SKILL.md +178 -0
  177. package/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
  178. package/.agent/skills/typescript-expert/SKILL.md +429 -0
  179. package/.agent/skills/typescript-expert/references/tsconfig-strict.json +92 -0
  180. package/.agent/skills/typescript-expert/references/typescript-cheatsheet.md +383 -0
  181. package/.agent/skills/typescript-expert/references/utility-types.ts +335 -0
  182. package/.agent/skills/typescript-expert/scripts/ts_diagnostic.py +203 -0
  183. package/.agent/skills/ui-ux-pro-max/SKILL.md +351 -0
  184. package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
  185. package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
  186. package/.agent/skills/ui-ux-pro-max/data/icons.csv +101 -0
  187. package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
  188. package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
  189. package/.agent/skills/ui-ux-pro-max/data/prompts.csv +24 -0
  190. package/.agent/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  191. package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  192. package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  193. package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  194. package/.agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  195. package/.agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  196. package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  197. package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  198. package/.agent/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  199. package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  200. package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  201. package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  202. package/.agent/skills/ui-ux-pro-max/data/styles.csv +59 -0
  203. package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
  204. package/.agent/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  205. package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  206. package/.agent/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  207. package/.agent/skills/ui-ux-pro-max/scripts/core.py +257 -0
  208. package/.agent/skills/ui-ux-pro-max/scripts/design_system.py +487 -0
  209. package/.agent/skills/ui-ux-pro-max/scripts/search.py +76 -0
  210. package/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
  211. package/.agent/skills/vulnerability-scanner/checklists.md +121 -0
  212. package/.agent/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
  213. package/.agent/skills/webapp-testing/SKILL.md +187 -0
  214. package/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
  215. package/.agent/templates/AGENTS.backend.md +230 -0
  216. package/.agent/templates/AGENTS.md +121 -0
  217. package/.agent/templates/AGENTS.mobile.md +183 -0
  218. package/.agent/templates/AGENTS.web.md +192 -0
  219. package/.agent/workflows/brainstorm.md +113 -0
  220. package/.agent/workflows/context.md +47 -0
  221. package/.agent/workflows/create.md +59 -0
  222. package/.agent/workflows/debug.md +103 -0
  223. package/.agent/workflows/deploy.md +176 -0
  224. package/.agent/workflows/enhance.md +63 -0
  225. package/.agent/workflows/orchestrate.md +237 -0
  226. package/.agent/workflows/plan.md +89 -0
  227. package/.agent/workflows/preview.md +80 -0
  228. package/.agent/workflows/quality.md +89 -0
  229. package/.agent/workflows/status.md +86 -0
  230. package/.agent/workflows/test.md +144 -0
  231. package/.agent/workflows/ui-ux-pro-max.md +250 -0
  232. package/LICENSE +21 -0
  233. package/README.md +317 -0
  234. package/bin/cli.js +1267 -0
  235. package/index.js +1 -0
  236. package/package.json +50 -0
@@ -0,0 +1,662 @@
1
+ ---
2
+ name: mcp-builder
3
+ description: MCP (Model Context Protocol) server building. Complete guide with TypeScript/Python examples, FastMCP, tool design, deployment patterns.
4
+ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
5
+ skills:
6
+ - typescript-expert
7
+ - python-patterns
8
+ ---
9
+
10
+ # MCP Builder
11
+
12
+ > Build production-ready MCP servers to extend AI capabilities with external tools and data.
13
+
14
+ ## 🔧 Quick Reference
15
+
16
+ | File | Purpose |
17
+ |------|---------|
18
+ | [typescript-template.md](typescript-template.md) | TypeScript MCP server template |
19
+ | [python-template.md](python-template.md) | FastMCP Python template |
20
+ | [tool-patterns.md](tool-patterns.md) | Tool design patterns & examples |
21
+
22
+ ---
23
+
24
+ ## 1. MCP Overview
25
+
26
+ ### What is MCP?
27
+
28
+ Model Context Protocol - the open standard for connecting AI systems with external tools, data sources, and services.
29
+
30
+ ```
31
+ ┌─────────────┐ MCP Protocol ┌─────────────────┐
32
+ │ AI Host │◄───────────────────►│ MCP Server │
33
+ │ (Claude) │ Tools/Resources │ (Your Service) │
34
+ └─────────────┘ └─────────────────┘
35
+ ```
36
+
37
+ ### Core Concepts
38
+
39
+ | Concept | Purpose | Example |
40
+ |---------|---------|---------|
41
+ | **Tools** | Functions AI can call | `get_weather`, `create_issue` |
42
+ | **Resources** | Data AI can read | Files, database records, APIs |
43
+ | **Prompts** | Pre-defined templates | Workflow shortcuts |
44
+
45
+ ### Why Build MCP Servers?
46
+
47
+ | Use Case | Example |
48
+ |----------|---------|
49
+ | **API Integration** | Connect to GitHub, Slack, Notion |
50
+ | **Database Access** | Query PostgreSQL, MongoDB |
51
+ | **File Operations** | Read/write local files |
52
+ | **Custom Tools** | Domain-specific automation |
53
+
54
+ ---
55
+
56
+ ## 2. TypeScript MCP Server
57
+
58
+ ### Quick Start
59
+
60
+ ```bash
61
+ # Create project
62
+ mkdir my-mcp-server && cd my-mcp-server
63
+ npm init -y
64
+ npm install @modelcontextprotocol/sdk zod
65
+ npm install -D typescript @types/node tsx
66
+
67
+ # Create structure
68
+ mkdir src
69
+ touch src/index.ts
70
+ ```
71
+
72
+ ### Basic Server Template
73
+
74
+ ```typescript
75
+ // src/index.ts
76
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
77
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
78
+ import { z } from "zod";
79
+
80
+ // Create server instance
81
+ const server = new McpServer({
82
+ name: "my-mcp-server",
83
+ version: "1.0.0",
84
+ });
85
+
86
+ // Define a tool
87
+ server.tool(
88
+ "greet",
89
+ "Greet a user by name",
90
+ {
91
+ name: z.string().describe("The user's name"),
92
+ },
93
+ async ({ name }) => {
94
+ return {
95
+ content: [
96
+ {
97
+ type: "text",
98
+ text: `Hello, ${name}! Welcome to MCP.`,
99
+ },
100
+ ],
101
+ };
102
+ }
103
+ );
104
+
105
+ // Define a resource
106
+ server.resource(
107
+ "status",
108
+ "status://server",
109
+ async (uri) => ({
110
+ contents: [
111
+ {
112
+ uri: uri.href,
113
+ mimeType: "application/json",
114
+ text: JSON.stringify({ status: "running", timestamp: new Date().toISOString() }),
115
+ },
116
+ ],
117
+ })
118
+ );
119
+
120
+ // Start server
121
+ async function main() {
122
+ const transport = new StdioServerTransport();
123
+ await server.connect(transport);
124
+ console.error("MCP Server running on stdio");
125
+ }
126
+
127
+ main().catch(console.error);
128
+ ```
129
+
130
+ ### Package.json Config
131
+
132
+ ```json
133
+ {
134
+ "name": "my-mcp-server",
135
+ "version": "1.0.0",
136
+ "type": "module",
137
+ "bin": {
138
+ "my-mcp-server": "./dist/index.js"
139
+ },
140
+ "scripts": {
141
+ "build": "tsc",
142
+ "dev": "tsx src/index.ts",
143
+ "start": "node dist/index.js"
144
+ },
145
+ "dependencies": {
146
+ "@modelcontextprotocol/sdk": "^1.0.0",
147
+ "zod": "^3.23.0"
148
+ },
149
+ "devDependencies": {
150
+ "@types/node": "^20.0.0",
151
+ "tsx": "^4.0.0",
152
+ "typescript": "^5.0.0"
153
+ }
154
+ }
155
+ ```
156
+
157
+ ---
158
+
159
+ ## 3. Python MCP Server (FastMCP)
160
+
161
+ ### Quick Start
162
+
163
+ ```bash
164
+ # Install FastMCP
165
+ pip install fastmcp
166
+
167
+ # Or with uv (recommended)
168
+ uv add fastmcp
169
+ ```
170
+
171
+ ### Basic Server Template
172
+
173
+ ```python
174
+ # server.py
175
+ from fastmcp import FastMCP
176
+
177
+ # Create server
178
+ mcp = FastMCP("My MCP Server")
179
+
180
+ # Define a tool
181
+ @mcp.tool()
182
+ def greet(name: str) -> str:
183
+ """Greet a user by name.
184
+
185
+ Args:
186
+ name: The user's name
187
+
188
+ Returns:
189
+ A greeting message
190
+ """
191
+ return f"Hello, {name}! Welcome to MCP."
192
+
193
+ # Define a tool with complex input
194
+ @mcp.tool()
195
+ def calculate(
196
+ operation: str,
197
+ a: float,
198
+ b: float
199
+ ) -> dict:
200
+ """Perform a mathematical calculation.
201
+
202
+ Args:
203
+ operation: One of 'add', 'subtract', 'multiply', 'divide'
204
+ a: First number
205
+ b: Second number
206
+
207
+ Returns:
208
+ Result of the calculation
209
+ """
210
+ ops = {
211
+ "add": lambda: a + b,
212
+ "subtract": lambda: a - b,
213
+ "multiply": lambda: a * b,
214
+ "divide": lambda: a / b if b != 0 else "Error: Division by zero",
215
+ }
216
+
217
+ if operation not in ops:
218
+ return {"error": f"Unknown operation: {operation}"}
219
+
220
+ return {"result": ops[operation](), "operation": operation}
221
+
222
+ # Define a resource
223
+ @mcp.resource("config://settings")
224
+ def get_settings() -> str:
225
+ """Get server configuration."""
226
+ import json
227
+ return json.dumps({
228
+ "version": "1.0.0",
229
+ "features": ["tools", "resources"],
230
+ })
231
+
232
+ # Define a prompt template
233
+ @mcp.prompt()
234
+ def code_review(code: str, language: str = "python") -> str:
235
+ """Generate a code review prompt."""
236
+ return f"""Please review this {language} code:
237
+
238
+ ```{language}
239
+ {code}
240
+ ```
241
+
242
+ Focus on:
243
+ 1. Code quality
244
+ 2. Potential bugs
245
+ 3. Performance
246
+ 4. Best practices"""
247
+
248
+ if __name__ == "__main__":
249
+ mcp.run()
250
+ ```
251
+
252
+ ### Running FastMCP
253
+
254
+ ```bash
255
+ # Development
256
+ fastmcp dev server.py
257
+
258
+ # Production
259
+ fastmcp run server.py
260
+
261
+ # Install to Claude Desktop
262
+ fastmcp install server.py --name "My Server"
263
+ ```
264
+
265
+ ---
266
+
267
+ ## 4. Tool Design Patterns
268
+
269
+ ### Pattern 1: CRUD Operations
270
+
271
+ ```python
272
+ @mcp.tool()
273
+ def create_task(title: str, description: str = "", priority: str = "medium") -> dict:
274
+ """Create a new task."""
275
+ task = {
276
+ "id": generate_id(),
277
+ "title": title,
278
+ "description": description,
279
+ "priority": priority,
280
+ "status": "pending",
281
+ "created_at": datetime.now().isoformat(),
282
+ }
283
+ save_task(task)
284
+ return {"success": True, "task": task}
285
+
286
+ @mcp.tool()
287
+ def get_task(task_id: str) -> dict:
288
+ """Get task by ID."""
289
+ task = load_task(task_id)
290
+ if not task:
291
+ return {"error": f"Task {task_id} not found"}
292
+ return task
293
+
294
+ @mcp.tool()
295
+ def update_task(task_id: str, status: str = None, priority: str = None) -> dict:
296
+ """Update task properties."""
297
+ # Implementation...
298
+
299
+ @mcp.tool()
300
+ def delete_task(task_id: str) -> dict:
301
+ """Delete a task."""
302
+ # Implementation...
303
+ ```
304
+
305
+ ### Pattern 2: API Integration
306
+
307
+ ```python
308
+ import httpx
309
+
310
+ @mcp.tool()
311
+ async def github_create_issue(
312
+ repo: str,
313
+ title: str,
314
+ body: str = "",
315
+ labels: list[str] = []
316
+ ) -> dict:
317
+ """Create a GitHub issue.
318
+
319
+ Args:
320
+ repo: Repository in format 'owner/repo'
321
+ title: Issue title
322
+ body: Issue body (markdown)
323
+ labels: List of label names
324
+ """
325
+ token = os.environ.get("GITHUB_TOKEN")
326
+ if not token:
327
+ return {"error": "GITHUB_TOKEN not set"}
328
+
329
+ async with httpx.AsyncClient() as client:
330
+ response = await client.post(
331
+ f"https://api.github.com/repos/{repo}/issues",
332
+ headers={
333
+ "Authorization": f"token {token}",
334
+ "Accept": "application/vnd.github.v3+json",
335
+ },
336
+ json={
337
+ "title": title,
338
+ "body": body,
339
+ "labels": labels,
340
+ }
341
+ )
342
+
343
+ if response.status_code == 201:
344
+ issue = response.json()
345
+ return {
346
+ "success": True,
347
+ "issue_number": issue["number"],
348
+ "url": issue["html_url"],
349
+ }
350
+ else:
351
+ return {"error": response.text}
352
+ ```
353
+
354
+ ### Pattern 3: Database Query
355
+
356
+ ```python
357
+ import sqlite3
358
+
359
+ @mcp.tool()
360
+ def query_database(sql: str, params: list = []) -> dict:
361
+ """Execute a read-only SQL query.
362
+
363
+ Args:
364
+ sql: SQL SELECT query
365
+ params: Query parameters (for safety)
366
+
367
+ Returns:
368
+ Query results as list of dicts
369
+ """
370
+ # Validate read-only
371
+ if not sql.strip().upper().startswith("SELECT"):
372
+ return {"error": "Only SELECT queries allowed"}
373
+
374
+ conn = sqlite3.connect("database.db")
375
+ conn.row_factory = sqlite3.Row
376
+
377
+ try:
378
+ cursor = conn.execute(sql, params)
379
+ rows = [dict(row) for row in cursor.fetchall()]
380
+ return {"rows": rows, "count": len(rows)}
381
+ except Exception as e:
382
+ return {"error": str(e)}
383
+ finally:
384
+ conn.close()
385
+ ```
386
+
387
+ ### Pattern 4: File Operations
388
+
389
+ ```python
390
+ from pathlib import Path
391
+
392
+ @mcp.tool()
393
+ def read_file(path: str) -> dict:
394
+ """Read a file's contents.
395
+
396
+ Args:
397
+ path: Relative path to file
398
+ """
399
+ file_path = Path(path).resolve()
400
+
401
+ # Security: validate path
402
+ if not file_path.is_relative_to(ALLOWED_DIR):
403
+ return {"error": "Access denied"}
404
+
405
+ if not file_path.exists():
406
+ return {"error": f"File not found: {path}"}
407
+
408
+ return {
409
+ "content": file_path.read_text(),
410
+ "size": file_path.stat().st_size,
411
+ "modified": file_path.stat().st_mtime,
412
+ }
413
+
414
+ @mcp.tool()
415
+ def write_file(path: str, content: str) -> dict:
416
+ """Write content to a file.
417
+
418
+ Args:
419
+ path: Relative path to file
420
+ content: Content to write
421
+ """
422
+ file_path = Path(path).resolve()
423
+
424
+ if not file_path.is_relative_to(ALLOWED_DIR):
425
+ return {"error": "Access denied"}
426
+
427
+ file_path.parent.mkdir(parents=True, exist_ok=True)
428
+ file_path.write_text(content)
429
+
430
+ return {"success": True, "path": str(file_path)}
431
+ ```
432
+
433
+ ---
434
+
435
+ ## 5. Claude Desktop Configuration
436
+
437
+ ### Config Location
438
+
439
+ | OS | Path |
440
+ |----|------|
441
+ | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
442
+ | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
443
+
444
+ ### Config Example
445
+
446
+ ```json
447
+ {
448
+ "mcpServers": {
449
+ "my-server": {
450
+ "command": "node",
451
+ "args": ["/path/to/my-mcp-server/dist/index.js"],
452
+ "env": {
453
+ "API_KEY": "your-api-key"
454
+ }
455
+ },
456
+ "python-server": {
457
+ "command": "python",
458
+ "args": ["/path/to/server.py"],
459
+ "env": {
460
+ "DATABASE_URL": "postgresql://..."
461
+ }
462
+ },
463
+ "fastmcp-server": {
464
+ "command": "fastmcp",
465
+ "args": ["run", "/path/to/server.py"]
466
+ }
467
+ }
468
+ }
469
+ ```
470
+
471
+ ---
472
+
473
+ ## 6. Best Practices
474
+
475
+ ### Tool Naming
476
+
477
+ | ❌ Bad | ✅ Good | Why |
478
+ |--------|---------|-----|
479
+ | `do_thing` | `create_user` | Specific action |
480
+ | `process` | `parse_csv` | Clear purpose |
481
+ | `handle_request` | `send_email` | Verb + noun |
482
+
483
+ ### Input Validation
484
+
485
+ ```python
486
+ @mcp.tool()
487
+ def send_email(
488
+ to: str,
489
+ subject: str,
490
+ body: str
491
+ ) -> dict:
492
+ """Send an email."""
493
+ # Validate email format
494
+ if not re.match(r"[^@]+@[^@]+\.[^@]+", to):
495
+ return {"error": "Invalid email format"}
496
+
497
+ # Validate subject length
498
+ if len(subject) > 200:
499
+ return {"error": "Subject too long (max 200 chars)"}
500
+
501
+ # ... send email
502
+ ```
503
+
504
+ ### Error Handling
505
+
506
+ ```python
507
+ @mcp.tool()
508
+ def risky_operation(param: str) -> dict:
509
+ """Operation that might fail."""
510
+ try:
511
+ result = do_something(param)
512
+ return {"success": True, "result": result}
513
+ except ValidationError as e:
514
+ return {"error": f"Invalid input: {e.message}"}
515
+ except PermissionError:
516
+ return {"error": "Permission denied"}
517
+ except Exception as e:
518
+ # Log internally, return generic message
519
+ logging.error(f"Unexpected error: {e}")
520
+ return {"error": "An unexpected error occurred"}
521
+ ```
522
+
523
+ ### Security Checklist
524
+
525
+ - [ ] Validate all inputs
526
+ - [ ] Use environment variables for secrets
527
+ - [ ] Limit file system access
528
+ - [ ] Sanitize SQL queries (use parameters)
529
+ - [ ] Rate limit expensive operations
530
+ - [ ] Log operations for audit
531
+
532
+ ---
533
+
534
+ ## 7. Deployment Options
535
+
536
+ ### Local (Claude Desktop)
537
+
538
+ ```bash
539
+ # Build and configure
540
+ npm run build
541
+ # Add to claude_desktop_config.json
542
+ ```
543
+
544
+ ### NPX Distribution
545
+
546
+ ```json
547
+ // package.json
548
+ {
549
+ "name": "@myorg/mcp-server",
550
+ "bin": {
551
+ "my-mcp-server": "./dist/index.js"
552
+ }
553
+ }
554
+ ```
555
+
556
+ ```bash
557
+ # Publish
558
+ npm publish --access public
559
+
560
+ # Users can run
561
+ npx @myorg/mcp-server
562
+ ```
563
+
564
+ ### Docker
565
+
566
+ ```dockerfile
567
+ FROM node:20-alpine
568
+ WORKDIR /app
569
+ COPY package*.json ./
570
+ RUN npm ci --production
571
+ COPY dist ./dist
572
+ CMD ["node", "dist/index.js"]
573
+ ```
574
+
575
+ ---
576
+
577
+ ## 8. Testing
578
+
579
+ ### Unit Test Example
580
+
581
+ ```typescript
582
+ import { describe, it, expect } from "vitest";
583
+ import { greetTool } from "./tools/greet";
584
+
585
+ describe("greet tool", () => {
586
+ it("should greet user by name", async () => {
587
+ const result = await greetTool({ name: "Alice" });
588
+ expect(result.content[0].text).toContain("Hello, Alice");
589
+ });
590
+
591
+ it("should handle empty name", async () => {
592
+ const result = await greetTool({ name: "" });
593
+ expect(result.content[0].text).toContain("error");
594
+ });
595
+ });
596
+ ```
597
+
598
+ ### Integration Test
599
+
600
+ ```bash
601
+ # Test with MCP Inspector
602
+ npx @modelcontextprotocol/inspector node dist/index.js
603
+ ```
604
+
605
+ ---
606
+
607
+ ## 9. Common Patterns
608
+
609
+ ### Progress Reporting
610
+
611
+ ```python
612
+ @mcp.tool()
613
+ async def long_running_task(items: list[str]) -> dict:
614
+ """Process items with progress updates."""
615
+ results = []
616
+
617
+ for i, item in enumerate(items):
618
+ # Process item
619
+ result = await process_item(item)
620
+ results.append(result)
621
+
622
+ # Report progress via logging
623
+ progress = (i + 1) / len(items) * 100
624
+ logging.info(f"Progress: {progress:.0f}%")
625
+
626
+ return {"results": results}
627
+ ```
628
+
629
+ ### Caching
630
+
631
+ ```python
632
+ from functools import lru_cache
633
+
634
+ @lru_cache(maxsize=100)
635
+ def expensive_lookup(key: str) -> dict:
636
+ """Cached database lookup."""
637
+ return db.query(key)
638
+
639
+ @mcp.tool()
640
+ def get_user(user_id: str) -> dict:
641
+ """Get user with caching."""
642
+ return expensive_lookup(user_id)
643
+ ```
644
+
645
+ ---
646
+
647
+ ## 10. Checklist
648
+
649
+ ### Before Publishing
650
+
651
+ - [ ] Clear, action-oriented tool names
652
+ - [ ] Complete input schemas with descriptions
653
+ - [ ] Structured JSON output
654
+ - [ ] Error handling for all cases
655
+ - [ ] Input validation
656
+ - [ ] Environment-based configuration
657
+ - [ ] README with installation instructions
658
+ - [ ] Tests for critical paths
659
+
660
+ ---
661
+
662
+ > **Remember:** MCP tools should be simple, focused, and well-documented. The AI relies on descriptions to use them correctly. Write tool descriptions as if explaining to a junior developer.