@koseha/api-mcp 0.0.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/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # API MCP 서버
2
+
3
+ Model Context Protocol (MCP) 서버입니다. 다른 프로젝트나 MCP 클라이언트에서 도구와 리소스를 제공합니다.
4
+
5
+ ## 기능
6
+
7
+ - **도구 (Tools)**: `add` - 두 숫자를 더하는 도구
8
+ - **리소스 (Resources)**: `greeting://{name}` - 동적 인사말 생성 리소스
9
+
10
+ ## 다른 프로젝트에서 사용하기
11
+
12
+ ### 방법 1: NPM 패키지로 배포하기
13
+
14
+ #### 1단계: 패키지 빌드
15
+
16
+ ```bash
17
+ npm run build
18
+ ```
19
+
20
+ #### 2단계: NPM에 배포 (선택사항)
21
+
22
+ ```bash
23
+ npm publish
24
+ ```
25
+
26
+ 또는 로컬 레지스트리나 private registry 사용
27
+
28
+ #### 3단계: 다른 프로젝트에서 설치
29
+
30
+ ```bash
31
+ cd ../다른-프로젝트
32
+ npm install api-mcp
33
+ ```
34
+
35
+ #### 4단계: 실행 파일로 사용
36
+
37
+ 다른 프로젝트에서 직접 실행:
38
+
39
+ ```javascript
40
+ import { spawn } from 'child_process';
41
+ import { join } from 'path';
42
+
43
+ const mcpServer = spawn('npx', ['api-mcp'], {
44
+ stdio: ['pipe', 'pipe', 'pipe']
45
+ });
46
+ ```
47
+
48
+ ### 방법 2: 로컬 패키지로 사용 (개발 중)
49
+
50
+ #### 1단계: npm link 설정
51
+
52
+ 현재 프로젝트에서:
53
+
54
+ ```bash
55
+ npm link
56
+ ```
57
+
58
+ #### 2단계: 다른 프로젝트에서 링크
59
+
60
+ 다른 프로젝트에서:
61
+
62
+ ```bash
63
+ cd ../다른-프로젝트
64
+ npm link api-mcp
65
+ ```
66
+
67
+ 이제 다른 프로젝트에서 `npx api-mcp` 명령어를 사용할 수 있습니다.
68
+
69
+ ### 방법 3: 상대 경로로 사용
70
+
71
+ 다른 프로젝트의 `package.json`에 추가:
72
+
73
+ ```json
74
+ {
75
+ "dependencies": {
76
+ "api-mcp": "file:../api-mcp"
77
+ }
78
+ }
79
+ ```
80
+
81
+ 그런 다음:
82
+
83
+ ```bash
84
+ npm install
85
+ ```
86
+
87
+ ### 방법 4: MCP 클라이언트에서 사용 (Claude Desktop 등)
88
+
89
+ #### Claude Desktop 설정
90
+
91
+ `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) 또는
92
+ `%APPDATA%\Claude\claude_desktop_config.json` (Windows) 파일에 추가:
93
+
94
+ ```json
95
+ {
96
+ "mcpServers": {
97
+ "api-mcp": {
98
+ "command": "node",
99
+ "args": ["C:/Users/saems/Desktop/project/mcps/api-mcp/dist/index.js"]
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ 또는 글로벌 설치 후:
106
+
107
+ ```json
108
+ {
109
+ "mcpServers": {
110
+ "api-mcp": {
111
+ "command": "npx",
112
+ "args": ["-y", "api-mcp"]
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ ### 방법 5: Node.js 프로젝트에서 직접 사용
119
+
120
+ 다른 Node.js 프로젝트에서:
121
+
122
+ ```javascript
123
+ // client.js
124
+ import { spawn } from 'child_process';
125
+ import { fileURLToPath } from 'url';
126
+ import { dirname, join } from 'path';
127
+
128
+ const __filename = fileURLToPath(import.meta.url);
129
+ const __dirname = dirname(__filename);
130
+
131
+ // MCP 서버 경로 (상대 또는 절대 경로)
132
+ const serverPath = join(__dirname, '../api-mcp/dist/index.js');
133
+
134
+ const mcpServer = spawn('node', [serverPath], {
135
+ stdio: ['pipe', 'pipe', 'pipe']
136
+ });
137
+
138
+ // JSON-RPC 요청 보내기
139
+ function sendRequest(method, params) {
140
+ const request = {
141
+ jsonrpc: '2.0',
142
+ id: Date.now(),
143
+ method,
144
+ params: params || {}
145
+ };
146
+ mcpServer.stdin?.write(JSON.stringify(request) + '\n');
147
+ }
148
+
149
+ // 응답 수신
150
+ let buffer = '';
151
+ mcpServer.stdout?.on('data', (data) => {
152
+ buffer += data.toString();
153
+ const lines = buffer.split('\n');
154
+ buffer = lines.pop() || '';
155
+
156
+ for (const line of lines) {
157
+ if (line.trim()) {
158
+ try {
159
+ const response = JSON.parse(line);
160
+ console.log('응답:', response);
161
+ } catch (e) {
162
+ // 파싱 오류 무시
163
+ }
164
+ }
165
+ }
166
+ });
167
+
168
+ // 초기화
169
+ sendRequest('initialize', {
170
+ protocolVersion: '2024-11-05',
171
+ capabilities: {
172
+ tools: {},
173
+ resources: {}
174
+ },
175
+ clientInfo: {
176
+ name: 'my-client',
177
+ version: '1.0.0'
178
+ }
179
+ });
180
+
181
+ // 도구 호출 예시
182
+ setTimeout(() => {
183
+ sendRequest('tools/call', {
184
+ name: 'add',
185
+ arguments: { a: 5, b: 3 }
186
+ });
187
+ }, 1000);
188
+ ```
189
+
190
+ ## 개발
191
+
192
+ ### 빌드
193
+
194
+ ```bash
195
+ npm run build
196
+ ```
197
+
198
+ ### 실행
199
+
200
+ ```bash
201
+ npm start
202
+ ```
203
+
204
+ ### 테스트 클라이언트 실행
205
+
206
+ ```bash
207
+ node test-client.js
208
+ ```
209
+
210
+ ## 프로젝트 구조
211
+
212
+ ```
213
+ api-mcp/
214
+ ├── src/
215
+ │ ├── index.ts # MCP 서버 메인 파일
216
+ │ └── tools/
217
+ │ └── listEndpoints.ts
218
+ ├── dist/
219
+ │ └── index.js # 빌드된 파일
220
+ ├── package.json
221
+ └── README.md
222
+ ```
223
+
224
+ ## 의존성
225
+
226
+ - `@modelcontextprotocol/sdk`: MCP SDK
227
+ - `zod`: 스키마 검증
228
+ - `typescript`: 타입스크립트 컴파일러
229
+
230
+ ## 참고 자료
231
+
232
+ - [MCP 공식 문서](https://modelcontextprotocol.io)
233
+ - [MCP SDK GitHub](https://github.com/modelcontextprotocol/typescript-sdk)
234
+
235
+
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import { McpServer, ResourceTemplate, } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ const server = new McpServer({
5
+ name: "api-mcp",
6
+ version: "1.0.0",
7
+ });
8
+ server.registerTool("add", {
9
+ title: "Addition Tool",
10
+ description: "Add two numbers",
11
+ inputSchema: { a: z.number(), b: z.number() },
12
+ }, async ({ a, b }) => ({
13
+ content: [{ type: "text", text: String(a + b) }],
14
+ }));
15
+ server.registerResource("greeting", new ResourceTemplate("greeting://{name}", { list: undefined }), {
16
+ title: "Greeting Resource",
17
+ description: "Dynamic greeting generator",
18
+ }, async (uri, { name }) => ({
19
+ contents: [{ uri: uri.href, text: `Hello, ${name}!` }],
20
+ }));
21
+ const transport = new StdioServerTransport();
22
+ await server.connect(transport);
23
+ console.log("MCP server is running via stdio.");
@@ -0,0 +1,5 @@
1
+ export function registerListEndpointsTool(server, endpoints) {
2
+ server.tool("list_endpoints", "List all API endpoints", {}, async () => {
3
+ return endpoints.map((e) => `${e.method} ${e.path}`);
4
+ });
5
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@koseha/api-mcp",
3
+ "version": "0.0.0",
4
+ "description": "An API MCP based on Swagger docs",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/koseha/api-mcp#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/koseha/api-mcp/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/koseha/api-mcp.git"
13
+ },
14
+ "license": "ISC",
15
+ "author": "koseha",
16
+ "type": "module",
17
+ "main": "index.js",
18
+ "bin": {
19
+ "api-mcp": "dist/index.js"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "start": "node dist/index.js",
24
+ "dev": "npm run build && npm run start"
25
+ },
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^1.25.1",
28
+ "yaml": "^2.8.2",
29
+ "zod": "^4.2.1"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^25.0.3",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.9.3"
35
+ }
36
+ }