Skip to content

Commit cddc281

Browse files
authored
Merge pull request #6 from microcmsio/feature/add-get-api-list
API一覧取得のツールを追加
2 parents 2d34e1f + 12f702f commit cddc281

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/client.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,23 @@ export async function getApiInfo(endpoint: string): Promise<any> {
106106
throw new Error(`Failed to get API info: ${response.status} ${response.statusText} - ${errorText}`);
107107
}
108108

109+
return await response.json();
110+
}
111+
112+
export async function getApiList(): Promise<any> {
113+
const url = `https://${config.serviceDomain}.microcms-management.io/api/v1/apis`;
114+
115+
const response = await fetch(url, {
116+
method: 'GET',
117+
headers: {
118+
'X-MICROCMS-API-KEY': config.apiKey,
119+
},
120+
});
121+
122+
if (!response.ok) {
123+
const errorText = await response.text();
124+
throw new Error(`Failed to get API list: ${response.status} ${response.statusText} - ${errorText}`);
125+
}
126+
109127
return await response.json();
110128
}

src/server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { deleteContentTool, handleDeleteContent } from './tools/delete-content.j
1616
import { getMediaTool, handleGetMedia } from './tools/get-media.js';
1717
import { uploadMediaTool, handleUploadMedia } from './tools/upload-media.js';
1818
import { getApiInfoTool, handleGetApiInfo } from './tools/get-api-info.js';
19+
import { getApiListTool, handleGetApiList } from './tools/get-apis-list.js';
1920
import type { ToolParameters, MediaToolParameters } from './types.js';
2021

2122
const server = new Server(
@@ -45,6 +46,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
4546
getMediaTool,
4647
uploadMediaTool,
4748
getApiInfoTool,
49+
getApiListTool,
4850
],
4951
};
5052
});
@@ -90,6 +92,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
9092
case 'microcms_get_api_info':
9193
result = await handleGetApiInfo(params);
9294
break;
95+
case 'microcms_get_api_list':
96+
result = await handleGetApiList(params);
97+
break;
9398
default:
9499
throw new Error(`Unknown tool: ${name}`);
95100
}

src/tools/get-apis-list.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
2+
import { getApiList as getApiList } from '../client.js';
3+
import type { ToolParameters } from '../types.js';
4+
5+
export const getApiListTool: Tool = {
6+
name: 'microcms_get_api_list',
7+
description: 'Get list of all available APIs (endpoints) from microCMS Management API. Returns API name, endpoint, and type (list/object) for each API.',
8+
inputSchema: {
9+
type: 'object',
10+
properties: {},
11+
required: [],
12+
},
13+
};
14+
15+
export async function handleGetApiList(params: ToolParameters) {
16+
return await getApiList();
17+
}

0 commit comments

Comments
 (0)