← Back to Skills Marketplace
49
Downloads
0
Stars
1
Active Installs
1
Versions
Install in OpenClaw
/install skylv-mcp-server-creator
Description
Build and run Model Context Protocol (MCP) servers with customizable tools and resources using TypeScript and the MCP SDK.
README (SKILL.md)
MCP Server Builder
功能说明
构建 Model Context Protocol 服务器,扩展 AI 能力边界。
MCP 协议概述
MCP 是 Anthropic 推出的 AI 模型上下文协议,让 AI 能调用外部工具和数据源。
项目结构
mcp-server/
├── package.json
├── tsconfig.json
├── src/
│ ├── index.ts # 主入口
│ ├── tools/ # 工具定义
│ └── resources/ # 资源定义
└── tsconfig.json
完整实现
1. 初始化项目
npm init -y
npm install @modelcontextprotocol/sdk zod
npm install -D typescript @types/node ts-node
// package.json
{
"name": "my-mcp-server",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "ts-node src/index.ts"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^0.5.0",
"zod": "^3.22.0"
}
}
// tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true
},
"include": ["src/**/*"]
}
2. 定义工具
// src/tools/search.ts
import { z } from 'zod';
export const searchTool = {
name: 'web_search',
description: '搜索互联网获取最新信息',
inputSchema: z.object({
query: z.string().describe('搜索关键词'),
limit: z.number().optional().default(5).describe('返回结果数量')
}),
async handler(args: { query: string; limit?: number }) {
// 实际实现
const results = await performSearch(args.query, args.limit || 5);
return {
content: results.map(r => ({
type: 'text' as const,
text: `标题: ${r.title}\
链接: ${r.url}\
摘要: ${r.snippet}`
}))
};
}
};
3. 定义资源
// src/resources/knowledge.ts
export const knowledgeResources = {
uriPrefix: 'knowledge://',
list: async () => [
{
uri: 'knowledge://docs/latest',
name: '最新文档',
description: '系统最新文档版本',
mimeType: 'text/markdown'
}
],
read: async (uri: string) => {
if (uri === 'knowledge://docs/latest') {
return {
contents: [{
uri,
mimeType: 'text/markdown',
text: '# 最新文档\
\
...'
}]
};
}
throw new Error('Resource not found');
}
};
4. 主入口
// src/index.ts
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
CallToolRequestSchema,
ListToolsRequestSchema,
ListResourcesRequestSchema,
ReadResourceRequestSchema
} from '@modelcontextprotocol/sdk/types.js';
import { searchTool } from './tools/search.js';
import { knowledgeResources } from './resources/knowledge.js';
class MyMCPServer {
private server: Server;
constructor() {
this.server = new Server(
{ name: 'my-mcp-server', version: '1.0.0' },
{ capabilities: { tools: {}, resources: {} } }
);
this.setupToolHandlers();
this.setupResourceHandlers();
}
private setupToolHandlers() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: searchTool.name,
description: searchTool.description,
inputSchema: searchTool.inputSchema
}
]
}));
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request.params;
if (name === 'web_search') {
return await searchTool.handler(args as any);
}
throw new Error(`Unknown tool: ${name}`);
});
}
private setupResourceHandlers() {
this.server.setRequestHandler(ListResourcesRequestSchema, async () => ({
resources: await knowledgeResources.list()
}));
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
return await knowledgeResources.read(request.params.uri);
});
}
async start() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.error('MCP Server started on stdio');
}
}
new MyMCPServer().start().catch(console.error);
5. 更多工具示例
// 文件操作工具
export const fileTools = {
name: 'file_operations',
description: '读取、写入、列出文件',
inputSchema: z.object({
operation: z.enum(['read', 'write', 'list', 'delete']),
path: z.string(),
content: z.string().optional()
}),
async handler(args: any) {
const fs = await import('fs/promises');
switch (args.operation) {
case 'read': {
const content = await fs.readFile(args.path, 'utf-8');
return { content: [{ type: 'text', text: content }] };
}
case 'write': {
await fs.writeFile(args.path, args.content || '');
return { content: [{ type: 'text', text: 'File written successfully' }] };
}
case 'list': {
const files = await fs.readdir(args.path);
return { content: [{ type: 'text', text: files.join('\
') }] };
}
default:
throw new Error(`Unknown operation: ${args.operation}`);
}
}
};
// 数据库查询工具
export const dbTool = {
name: 'database_query',
description: '执行数据库查询',
inputSchema: z.object({
sql: z.string().describe('SQL查询语句'),
params: z.array(z.any()).optional()
}),
async handler(args: any) {
// 使用 mysql2 或 pg
// const pool = new Pool({ connectionString: process.env.DATABASE_URL });
// const result = await pool.query(args.sql, args.params);
return {
content: [{ type: 'text', text: JSON.stringify({ rows: [], count: 0 }) }]
};
}
};
测试
# 编译
npm run build
# 手动测试
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | npm run dev
# MCP Inspector
npx @modelcontextprotocol/inspector npm run dev
部署
Claude Desktop
// ~/.config/claude-desktop/claude_desktop_config.json
{
"mcpServers": {
"my-mcp-server": {
"command": "node",
"args": ["/path/to/mcp-server/dist/index.js"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
Cursor / VS Code
在扩展设置中添加 MCP 服务器路径。
最佳实践
- 错误处理:始终返回有意义的错误信息
- 类型安全:使用 Zod 严格验证输入
- 日志记录:使用
console.error记录关键事件 - 性能:长时间操作使用流式响应
- 安全:不记录敏感信息,定期清理日志
Usage
- Install the skill
- Configure as needed
- Run with OpenClaw
Usage Guidance
Review the generated MCP tools before running them. The basic MCP scaffolding is expected, but do not copy the unrestricted file or database examples into a live server without limiting paths, database privileges, allowed operations, and requiring confirmation for writes or destructive actions.
Capability Analysis
Type: OpenClaw Skill
Name: skylv-mcp-server-creator
Version: 1.0.0
The skill provides boilerplate code for building MCP servers that includes high-risk capabilities such as arbitrary file system operations (read, write, delete) and raw SQL execution in the 'fileTools' and 'dbTool' examples within SKILL.md. While these features align with the stated purpose of a server builder, the provided code lacks input sanitization or path validation, creating significant vulnerabilities like Path Traversal and SQL Injection if an AI agent implements them as written.
Capability Tags
Capability Assessment
Purpose & Capability
The stated MCP server-building purpose matches the instructions, but the provided tool templates include broad file and database capabilities without safety boundaries.
Instruction Scope
Most commands are user-directed setup steps, but the example MCP tools accept raw file paths and SQL strings from tool callers without allowlists, confirmations, or read-only limits.
Install Mechanism
There is no install spec or bundled executable code. The skill tells users to run npm install commands for expected MCP/TypeScript packages, but dependency versions are not tightly pinned.
Credentials
The file tool is not scoped to a project directory, and the database example could inherit whatever authority is granted through DATABASE_URL.
Persistence & Privilege
The sample starts an MCP server over stdio only when the user runs it; no autostart or hidden persistence is shown. Optional database credentials should still be least-privileged.
How to Use
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install skylv-mcp-server-creator - After installation, invoke the skill by name or use
/skylv-mcp-server-creator - Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
- Initial release as "mcp-server-builder" (version 1.0.2), providing a complete scaffolding template for building Model Context Protocol (MCP) servers.
- Features detailed instructions and code samples for defining tools, resources, and handlers in a TypeScript MCP server project.
- Includes best practices for error handling, type safety, logging, and deployment in environments like Claude Desktop and VS Code.
- Offers example implementations for web search, file operations, and database query tools.
- Supports local testing and integration with OpenClaw and MCP Inspector.
Metadata
Frequently Asked Questions
What is Skylv Mcp Server Creator?
Build and run Model Context Protocol (MCP) servers with customizable tools and resources using TypeScript and the MCP SDK. It is an AI Agent Skill for Claude Code / OpenClaw, with 49 downloads so far.
How do I install Skylv Mcp Server Creator?
Run "/install skylv-mcp-server-creator" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Skylv Mcp Server Creator free?
Yes, Skylv Mcp Server Creator is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Skylv Mcp Server Creator support?
Skylv Mcp Server Creator is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Skylv Mcp Server Creator?
It is built and maintained by SKY-lv (@sky-lv); the current version is v1.0.0.
More Skills