mcp_openai_embedding
Generate text embeddings using OpenAI's API for integration with Ontology MCP, enabling AI models to process and analyze textual data within semantic frameworks.
Instructions
OpenAI Embeddings API를 사용하여 텍스트 임베딩을 생성합니다
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dimensions | No | 임베딩 차원 수 (API가 지원하는 경우) | |
| model | No | 사용할 모델 (예: text-embedding-3-small, text-embedding-3-large) | |
| text | Yes | 임베딩을 생성할 텍스트 또는 텍스트 배열 |
Input Schema (JSON Schema)
{
"properties": {
"dimensions": {
"description": "임베딩 차원 수 (API가 지원하는 경우)",
"type": "number"
},
"model": {
"description": "사용할 모델 (예: text-embedding-3-small, text-embedding-3-large)",
"type": "string"
},
"text": {
"description": "임베딩을 생성할 텍스트 또는 텍스트 배열",
"type": [
"string",
"array"
]
}
},
"required": [
"text"
],
"type": "object"
}
Implementation Reference
- src/services/openai-service.ts:320-369 (handler)Core handler implementation: Calls OpenAI Embeddings API (/v1/embeddings) with text input, model, and optional dimensions, returns JSON of response data./** * Embeddings API를 사용하여 텍스트 임베딩을 생성합니다 */ async generateEmbeddings(args: { text: string | string[]; model?: string; dimensions?: number; }): Promise<string> { try { if (!OPENAI_API_KEY) { throw new McpError( ErrorCode.InternalError, 'OPENAI_API_KEY가 설정되지 않았습니다.' ); } const response = await axios.post( `${OPENAI_API_BASE}/embeddings`, { model: args.model || 'text-embedding-3-small', input: args.text, dimensions: args.dimensions }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` } } ); return JSON.stringify(response.data, null, 2); } catch (error) { if (axios.isAxiosError(error)) { const statusCode = error.response?.status; const responseData = error.response?.data; throw new McpError( ErrorCode.InternalError, `OpenAI API 오류 (${statusCode}): ${ typeof responseData === 'object' ? JSON.stringify(responseData, null, 2) : responseData || error.message }` ); } throw new McpError(ErrorCode.InternalError, `임베딩 생성 요청 실패: ${formatError(error)}`); } }
- src/tools/index.ts:762-800 (registration)Tool registration: Defines name, description, input schema, and thin handler that delegates to openaiService.generateEmbeddings.name: 'mcp_openai_embedding', description: 'OpenAI Embeddings API를 사용하여 텍스트 임베딩을 생성합니다', inputSchema: { type: 'object', properties: { text: { type: ['string', 'array'], description: '임베딩을 생성할 텍스트 또는 텍스트 배열' }, model: { type: 'string', description: '사용할 모델 (예: text-embedding-3-small, text-embedding-3-large)' }, dimensions: { type: 'number', description: '임베딩 차원 수 (API가 지원하는 경우)' } }, required: ['text'] }, async handler(args: any): Promise<ToolResponse> { try { const result = await openaiService.generateEmbeddings(args); return { content: [{ type: 'text', text: result }] }; } catch (error) { return { content: [{ type: 'text', text: `OpenAI 임베딩 오류: ${error instanceof Error ? error.message : String(error)}` }] }; } } },
- src/tools/index.ts:764-781 (schema)Input schema validation for the tool: requires 'text', optional 'model' and 'dimensions'.inputSchema: { type: 'object', properties: { text: { type: ['string', 'array'], description: '임베딩을 생성할 텍스트 또는 텍스트 배열' }, model: { type: 'string', description: '사용할 모델 (예: text-embedding-3-small, text-embedding-3-large)' }, dimensions: { type: 'number', description: '임베딩 차원 수 (API가 지원하는 경우)' } }, required: ['text'] },
- src/index.ts:43-43 (registration)Tool enabled (true) in the main server configuration flags.mcp_openai_embedding: true,