feat: Context7 라이브러리 문서 조회 Function Calling 추가
- lookup_docs 도구로 React, OpenAI 등 공식 문서 실시간 조회 - README에 Context7 연동 기능 문서화 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -93,6 +93,27 @@ const tools = [
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'lookup_docs',
|
||||
description: '프로그래밍 라이브러리의 공식 문서를 조회합니다. React, OpenAI, Cloudflare Workers 등의 최신 문서와 코드 예제를 검색할 수 있습니다.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
library: {
|
||||
type: 'string',
|
||||
description: '라이브러리 이름 (예: react, openai, cloudflare-workers, next.js)',
|
||||
},
|
||||
query: {
|
||||
type: 'string',
|
||||
description: '찾고 싶은 내용 (예: hooks 사용법, API 호출 방법)',
|
||||
},
|
||||
},
|
||||
required: ['library', 'query'],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 도구 실행
|
||||
@@ -162,6 +183,38 @@ async function executeTool(name: string, args: Record<string, string>): Promise<
|
||||
}
|
||||
}
|
||||
|
||||
case 'lookup_docs': {
|
||||
const library = args.library;
|
||||
const query = args.query;
|
||||
try {
|
||||
// Context7 REST API 직접 호출
|
||||
// 1. 라이브러리 검색
|
||||
const searchUrl = `https://context7.com/api/v2/libs/search?libraryName=${encodeURIComponent(library)}&query=${encodeURIComponent(query)}`;
|
||||
const searchResponse = await fetch(searchUrl);
|
||||
const searchData = await searchResponse.json() as any;
|
||||
|
||||
if (!searchData.libraries?.length) {
|
||||
return `📚 "${library}" 라이브러리를 찾을 수 없습니다.`;
|
||||
}
|
||||
|
||||
const libraryId = searchData.libraries[0].id;
|
||||
|
||||
// 2. 문서 조회
|
||||
const docsUrl = `https://context7.com/api/v2/context?libraryId=${encodeURIComponent(libraryId)}&query=${encodeURIComponent(query)}`;
|
||||
const docsResponse = await fetch(docsUrl);
|
||||
const docsData = await docsResponse.json() as any;
|
||||
|
||||
if (docsData.error) {
|
||||
return `📚 문서 조회 실패: ${docsData.message || docsData.error}`;
|
||||
}
|
||||
|
||||
const content = docsData.context || docsData.content || JSON.stringify(docsData, null, 2);
|
||||
return `📚 ${library} 문서 (${query}):\n\n${content.slice(0, 1500)}`;
|
||||
} catch (error) {
|
||||
return `📚 문서 조회 중 오류: ${String(error)}`;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return `알 수 없는 도구: ${name}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user