@isnow890/naver-search-mcp 1.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/LICENSE +21 -0
- package/README.md +166 -0
- package/dist/src/handlers/datalab.handlers.js +104 -0
- package/dist/src/handlers/search.handlers.js +79 -0
- package/dist/src/index.js +154 -0
- package/dist/src/naver-search.client.js +155 -0
- package/dist/src/schemas/datalab.schemas.js +103 -0
- package/dist/src/schemas/search.schemas.js +17 -0
- package/dist/src/tools/datalab.tools.js +70 -0
- package/dist/src/tools/search.tools.js +58 -0
- package/dist/src/types/naver-search.types.js +61 -0
- package/dist/src/utils/image-processor.js +61 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 isnow890
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Naver Search MCP Server
|
|
2
|
+
|
|
3
|
+
[](README-ko.md)
|
|
4
|
+
[](https://smithery.ai/server/@isnow890/naver-search-mcp)
|
|
5
|
+
[](https://mcp.so/server/naver-search-mcp/isnow890)
|
|
6
|
+
|
|
7
|
+
MCP server for Naver Search API and DataLab API integration, enabling comprehensive search across various Naver services and data trend analysis.
|
|
8
|
+
|
|
9
|
+
#### Prerequisites
|
|
10
|
+
|
|
11
|
+
- Naver Developers API Key (Client ID and Secret)
|
|
12
|
+
- Node.js 18 or higher
|
|
13
|
+
- NPM 8 or higher
|
|
14
|
+
- Docker (optional, for container deployment)
|
|
15
|
+
|
|
16
|
+
#### Getting API Keys
|
|
17
|
+
|
|
18
|
+
1. Visit [Naver Developers](https://developers.naver.com/apps/#/register)
|
|
19
|
+
2. Click "Register Application"
|
|
20
|
+
3. Enter application name and select ALL of the following APIs:
|
|
21
|
+
- Search (for blog, news, book search, etc.)
|
|
22
|
+
- DataLab (Search Trends)
|
|
23
|
+
- DataLab (Shopping Insight)
|
|
24
|
+
4. Set the obtained Client ID and Client Secret as environment variables
|
|
25
|
+
|
|
26
|
+
## Tool Details
|
|
27
|
+
|
|
28
|
+
### Available tools:
|
|
29
|
+
|
|
30
|
+
- **search_webkr**: Search Naver web documents
|
|
31
|
+
- **search_news**: Search Naver news
|
|
32
|
+
- **search_blog**: Search Naver blogs
|
|
33
|
+
- **search_shop**: Search Naver shopping
|
|
34
|
+
- **search_image**: Search Naver images
|
|
35
|
+
- **search_kin**: Search Naver KnowledgeiN
|
|
36
|
+
- **search_book**: Search Naver books
|
|
37
|
+
- **search_encyc**: Search Naver encyclopedia
|
|
38
|
+
- **search_academic**: Search Naver academic papers
|
|
39
|
+
- **search_local**: Search Naver local places
|
|
40
|
+
- **datalab_search**: Analyze search term trends
|
|
41
|
+
- **datalab_shopping_category**: Analyze shopping category trends
|
|
42
|
+
- **datalab_shopping_by_device**: Analyze shopping trends by device
|
|
43
|
+
- **datalab_shopping_by_gender**: Analyze shopping trends by gender
|
|
44
|
+
- **datalab_shopping_by_age**: Analyze shopping trends by age group
|
|
45
|
+
- **datalab_shopping_keywords**: Analyze shopping keyword trends
|
|
46
|
+
- **datalab_shopping_keyword_by_device**: Analyze shopping keyword trends by device
|
|
47
|
+
- **datalab_shopping_keyword_by_gender**: Analyze shopping keyword trends by gender
|
|
48
|
+
- **datalab_shopping_keyword_by_age**: Analyze shopping keyword trends by age group
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
### Option 1: Quick Install via Smithery (Recommended)
|
|
53
|
+
|
|
54
|
+
To install Naver Search MCP Server automatically via Smithery, use one of these commands based on your AI client:
|
|
55
|
+
|
|
56
|
+
For Claude Desktop:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client claude
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For Cursor:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client cursor
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
For Windsurf:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client windsurf
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For Cline:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client cline
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The installer will prompt you for:
|
|
81
|
+
|
|
82
|
+
- NAVER_CLIENT_ID
|
|
83
|
+
- NAVER_CLIENT_SECRET
|
|
84
|
+
|
|
85
|
+
### Option 2: Manual Installation
|
|
86
|
+
|
|
87
|
+
#### Environment Variables
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Windows
|
|
91
|
+
set NAVER_CLIENT_ID=your_client_id
|
|
92
|
+
set NAVER_CLIENT_SECRET=your_client_secret
|
|
93
|
+
|
|
94
|
+
# Linux/Mac
|
|
95
|
+
export NAVER_CLIENT_ID=your_client_id
|
|
96
|
+
export NAVER_CLIENT_SECRET=your_client_secret
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Run with NPX
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npx @modelcontextprotocol/server-naver-search
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Run with Docker
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
docker run -i --rm \
|
|
109
|
+
-e NAVER_CLIENT_ID=your_client_id \
|
|
110
|
+
-e NAVER_CLIENT_SECRET=your_client_secret \
|
|
111
|
+
mcp/naver-search
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Cursor Desktop Configuration
|
|
115
|
+
|
|
116
|
+
Add to `claude_desktop_config.json`:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"mcpServers": {
|
|
121
|
+
"naver-search": {
|
|
122
|
+
"command": "npx",
|
|
123
|
+
"args": ["-y", "@modelcontextprotocol/server-naver-search"],
|
|
124
|
+
"env": {
|
|
125
|
+
"NAVER_CLIENT_ID": "your_client_id",
|
|
126
|
+
"NAVER_CLIENT_SECRET": "your_client_secret"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
For Docker:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"mcpServers": {
|
|
138
|
+
"naver-search": {
|
|
139
|
+
"command": "docker",
|
|
140
|
+
"args": [
|
|
141
|
+
"run",
|
|
142
|
+
"-i",
|
|
143
|
+
"--rm",
|
|
144
|
+
"-e",
|
|
145
|
+
"NAVER_CLIENT_ID=your_client_id",
|
|
146
|
+
"-e",
|
|
147
|
+
"NAVER_CLIENT_SECRET=your_client_secret",
|
|
148
|
+
"mcp/naver-search"
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
## Build
|
|
155
|
+
|
|
156
|
+
Docker build:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
docker build -t mcp/naver-search .
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT License
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { NaverSearchClient } from "../naver-search.client.js";
|
|
2
|
+
// 클라이언트 인스턴스
|
|
3
|
+
const client = NaverSearchClient.getInstance();
|
|
4
|
+
/**
|
|
5
|
+
* 검색어 트렌드 핸들러
|
|
6
|
+
*/
|
|
7
|
+
export async function handleSearchTrend(params) {
|
|
8
|
+
return client.searchTrend(params);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 쇼핑 카테고리 트렌드 핸들러
|
|
12
|
+
*/
|
|
13
|
+
export async function handleShoppingCategoryTrend(params) {
|
|
14
|
+
return client.datalabShoppingCategory(params);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 쇼핑 기기별 트렌드 핸들러
|
|
18
|
+
*/
|
|
19
|
+
export async function handleShoppingByDeviceTrend(params) {
|
|
20
|
+
return client.datalabShoppingByDevice({
|
|
21
|
+
startDate: params.startDate,
|
|
22
|
+
endDate: params.endDate,
|
|
23
|
+
timeUnit: params.timeUnit,
|
|
24
|
+
category: params.category,
|
|
25
|
+
device: params.device,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 쇼핑 성별 트렌드 핸들러
|
|
30
|
+
*/
|
|
31
|
+
export async function handleShoppingByGenderTrend(params) {
|
|
32
|
+
return client.datalabShoppingByGender({
|
|
33
|
+
startDate: params.startDate,
|
|
34
|
+
endDate: params.endDate,
|
|
35
|
+
timeUnit: params.timeUnit,
|
|
36
|
+
category: params.category,
|
|
37
|
+
gender: params.gender,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 쇼핑 연령별 트렌드 핸들러
|
|
42
|
+
*/
|
|
43
|
+
export async function handleShoppingByAgeTrend(params) {
|
|
44
|
+
return client.datalabShoppingByAge({
|
|
45
|
+
startDate: params.startDate,
|
|
46
|
+
endDate: params.endDate,
|
|
47
|
+
timeUnit: params.timeUnit,
|
|
48
|
+
category: params.category,
|
|
49
|
+
ages: params.ages,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 쇼핑 키워드 트렌드 핸들러
|
|
54
|
+
* 복수 키워드 그룹을 지원합니다.
|
|
55
|
+
*/
|
|
56
|
+
export async function handleShoppingKeywordsTrend(params) {
|
|
57
|
+
// 키워드 배열을 네이버 API에 맞는 형식으로 변환
|
|
58
|
+
return client.datalabShoppingKeywords({
|
|
59
|
+
startDate: params.startDate,
|
|
60
|
+
endDate: params.endDate,
|
|
61
|
+
timeUnit: params.timeUnit,
|
|
62
|
+
category: params.category,
|
|
63
|
+
keyword: params.keyword
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 쇼핑 키워드 기기별 트렌드 핸들러
|
|
68
|
+
*/
|
|
69
|
+
export async function handleShoppingKeywordByDeviceTrend(params) {
|
|
70
|
+
return client.datalabShoppingKeywordByDevice({
|
|
71
|
+
startDate: params.startDate,
|
|
72
|
+
endDate: params.endDate,
|
|
73
|
+
timeUnit: params.timeUnit,
|
|
74
|
+
category: params.category,
|
|
75
|
+
keyword: params.keyword,
|
|
76
|
+
device: params.device,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 쇼핑 키워드 성별 트렌드 핸들러
|
|
81
|
+
*/
|
|
82
|
+
export async function handleShoppingKeywordByGenderTrend(params) {
|
|
83
|
+
return client.datalabShoppingKeywordByGender({
|
|
84
|
+
startDate: params.startDate,
|
|
85
|
+
endDate: params.endDate,
|
|
86
|
+
timeUnit: params.timeUnit,
|
|
87
|
+
category: params.category,
|
|
88
|
+
keyword: params.keyword,
|
|
89
|
+
gender: params.gender,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 쇼핑 키워드 연령별 트렌드 핸들러
|
|
94
|
+
*/
|
|
95
|
+
export async function handleShoppingKeywordByAgeTrend(params) {
|
|
96
|
+
return client.datalabShoppingKeywordByAge({
|
|
97
|
+
startDate: params.startDate,
|
|
98
|
+
endDate: params.endDate,
|
|
99
|
+
timeUnit: params.timeUnit,
|
|
100
|
+
category: params.category,
|
|
101
|
+
keyword: params.keyword,
|
|
102
|
+
ages: params.ages,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { NaverSearchClient } from "../naver-search.client.js";
|
|
2
|
+
// 클라이언트 인스턴스
|
|
3
|
+
const client = NaverSearchClient.getInstance();
|
|
4
|
+
/**
|
|
5
|
+
* 기본 검색 핸들러
|
|
6
|
+
*/
|
|
7
|
+
export async function handleSearch(params) {
|
|
8
|
+
return client.search({ ...params });
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 전문자료 검색 핸들러
|
|
12
|
+
*/
|
|
13
|
+
export async function handleAcademicSearch(params) {
|
|
14
|
+
return client.searchAcademic(params);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 도서 검색 핸들러
|
|
18
|
+
*/
|
|
19
|
+
export async function handleBookSearch(params) {
|
|
20
|
+
return client.search({ type: "book", ...params });
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 지식백과 검색 핸들러
|
|
24
|
+
*/
|
|
25
|
+
export async function handleEncycSearch(params) {
|
|
26
|
+
return client.search({ type: "encyc", ...params });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 이미지 검색 핸들러
|
|
30
|
+
*/
|
|
31
|
+
export async function handleImageSearch(params) {
|
|
32
|
+
return client.search({ type: "image", ...params });
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 지식iN 검색 핸들러
|
|
36
|
+
*/
|
|
37
|
+
export async function handleKinSearch(params) {
|
|
38
|
+
return client.search({ type: "kin", ...params });
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 지역 검색 핸들러
|
|
42
|
+
*/
|
|
43
|
+
export async function handleLocalSearch(params) {
|
|
44
|
+
return client.searchLocal(params);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 뉴스 검색 핸들러
|
|
48
|
+
*/
|
|
49
|
+
export async function handleNewsSearch(params) {
|
|
50
|
+
return client.search({ type: "news", ...params });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 블로그 검색 핸들러
|
|
54
|
+
*/
|
|
55
|
+
export async function handleBlogSearch(params) {
|
|
56
|
+
return client.search({ type: "blog", ...params });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 쇼핑 검색 핸들러
|
|
60
|
+
*/
|
|
61
|
+
export async function handleShopSearch(params) {
|
|
62
|
+
return client.search({ type: "shop", ...params });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 웹문서 검색 핸들러
|
|
66
|
+
*/
|
|
67
|
+
export async function handleWebSearch(params) {
|
|
68
|
+
return client.search({ type: "webkr", ...params });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 카페글 검색 핸들러
|
|
72
|
+
*/
|
|
73
|
+
export async function handleCafeArticleSearch(params) {
|
|
74
|
+
return client.search({ type: "cafearticle", ...params });
|
|
75
|
+
}
|
|
76
|
+
export async function handleWebKrSearch(args) {
|
|
77
|
+
const client = NaverSearchClient.getInstance();
|
|
78
|
+
return await client.search({ type: "webkr", ...args });
|
|
79
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as dotenv from "dotenv";
|
|
3
|
+
dotenv.config();
|
|
4
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
7
|
+
import { NaverSearchClient } from "./naver-search.client.js";
|
|
8
|
+
import { SearchArgsSchema } from "./schemas/search.schemas.js";
|
|
9
|
+
import { searchTools } from "./tools/search.tools.js";
|
|
10
|
+
import { datalabTools } from "./tools/datalab.tools.js";
|
|
11
|
+
import { handleAcademicSearch, handleBlogSearch, handleBookSearch, handleEncycSearch, handleImageSearch, handleKinSearch, handleLocalSearch, handleNewsSearch, handleShopSearch, handleWebKrSearch, } from "./handlers/search.handlers.js";
|
|
12
|
+
import { handleSearchTrend, handleShoppingByAgeTrend, handleShoppingByDeviceTrend, handleShoppingByGenderTrend, handleShoppingCategoryTrend, handleShoppingKeywordByAgeTrend, handleShoppingKeywordByDeviceTrend, handleShoppingKeywordByGenderTrend, handleShoppingKeywordsTrend, } from "./handlers/datalab.handlers.js";
|
|
13
|
+
// 환경 변수 유효성 검사
|
|
14
|
+
const NAVER_CLIENT_ID = process.env.NAVER_CLIENT_ID;
|
|
15
|
+
const NAVER_CLIENT_SECRET = process.env.NAVER_CLIENT_SECRET;
|
|
16
|
+
if (!NAVER_CLIENT_ID || !NAVER_CLIENT_SECRET) {
|
|
17
|
+
console.error("Error: NAVER_CLIENT_ID and NAVER_CLIENT_SECRET environment variables are required");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
// 네이버 검색 클라이언트 초기화
|
|
21
|
+
const client = NaverSearchClient.getInstance();
|
|
22
|
+
client.initialize({
|
|
23
|
+
clientId: NAVER_CLIENT_ID,
|
|
24
|
+
clientSecret: NAVER_CLIENT_SECRET,
|
|
25
|
+
});
|
|
26
|
+
// MCP 서버 인스턴스 생성
|
|
27
|
+
const server = new Server({
|
|
28
|
+
name: "naver-search",
|
|
29
|
+
version: "1.0.0",
|
|
30
|
+
}, {
|
|
31
|
+
capabilities: {
|
|
32
|
+
tools: {},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
// 도구 목록을 반환하는 핸들러 등록
|
|
36
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
37
|
+
return {
|
|
38
|
+
tools: [...searchTools, ...datalabTools],
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
// 에러 응답 헬퍼 함수
|
|
42
|
+
function createErrorResponse(error) {
|
|
43
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
44
|
+
console.error("API Error:", errorMessage);
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: "text", text: `Error: ${errorMessage}` }],
|
|
47
|
+
isError: true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// 도구 실행 요청 핸들러 등록
|
|
51
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
52
|
+
try {
|
|
53
|
+
const { name, arguments: args } = request.params;
|
|
54
|
+
console.error(`Executing tool: ${name} with args:`, args);
|
|
55
|
+
if (!args) {
|
|
56
|
+
throw new Error("Arguments are required");
|
|
57
|
+
}
|
|
58
|
+
let result;
|
|
59
|
+
switch (name) {
|
|
60
|
+
// 검색 API
|
|
61
|
+
case "search_webkr":
|
|
62
|
+
result = await handleWebKrSearch(SearchArgsSchema.parse(args));
|
|
63
|
+
break;
|
|
64
|
+
case "search_news":
|
|
65
|
+
result = await handleNewsSearch(SearchArgsSchema.parse(args));
|
|
66
|
+
break;
|
|
67
|
+
case "search_blog":
|
|
68
|
+
result = await handleBlogSearch(SearchArgsSchema.parse(args));
|
|
69
|
+
break;
|
|
70
|
+
case "search_shop":
|
|
71
|
+
result = await handleShopSearch(SearchArgsSchema.parse(args));
|
|
72
|
+
break;
|
|
73
|
+
case "search_image":
|
|
74
|
+
result = await handleImageSearch(SearchArgsSchema.parse(args));
|
|
75
|
+
break;
|
|
76
|
+
case "search_kin":
|
|
77
|
+
result = await handleKinSearch(SearchArgsSchema.parse(args));
|
|
78
|
+
break;
|
|
79
|
+
case "search_book":
|
|
80
|
+
result = await handleBookSearch(SearchArgsSchema.parse(args));
|
|
81
|
+
break;
|
|
82
|
+
case "search_encyc":
|
|
83
|
+
result = await handleEncycSearch(SearchArgsSchema.parse(args));
|
|
84
|
+
break;
|
|
85
|
+
case "search_academic":
|
|
86
|
+
result = await handleAcademicSearch(SearchArgsSchema.parse(args));
|
|
87
|
+
break;
|
|
88
|
+
case "search_local":
|
|
89
|
+
result = await handleLocalSearch(args);
|
|
90
|
+
break;
|
|
91
|
+
// 데이터랩 API
|
|
92
|
+
case "datalab_search":
|
|
93
|
+
result = await handleSearchTrend(args);
|
|
94
|
+
break;
|
|
95
|
+
case "datalab_shopping_category":
|
|
96
|
+
result = await handleShoppingCategoryTrend(args);
|
|
97
|
+
break;
|
|
98
|
+
case "datalab_shopping_by_device":
|
|
99
|
+
result = await handleShoppingByDeviceTrend(args);
|
|
100
|
+
break;
|
|
101
|
+
case "datalab_shopping_by_gender":
|
|
102
|
+
result = await handleShoppingByGenderTrend(args);
|
|
103
|
+
break;
|
|
104
|
+
case "datalab_shopping_by_age":
|
|
105
|
+
result = await handleShoppingByAgeTrend(args);
|
|
106
|
+
break;
|
|
107
|
+
case "datalab_shopping_keywords":
|
|
108
|
+
result = await handleShoppingKeywordsTrend(args);
|
|
109
|
+
break;
|
|
110
|
+
case "datalab_shopping_keyword_by_device":
|
|
111
|
+
result = await handleShoppingKeywordByDeviceTrend(args);
|
|
112
|
+
break;
|
|
113
|
+
case "datalab_shopping_keyword_by_gender":
|
|
114
|
+
result = await handleShoppingKeywordByGenderTrend(args);
|
|
115
|
+
break;
|
|
116
|
+
case "datalab_shopping_keyword_by_age":
|
|
117
|
+
result = await handleShoppingKeywordByAgeTrend(args);
|
|
118
|
+
break;
|
|
119
|
+
default:
|
|
120
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
121
|
+
}
|
|
122
|
+
console.error(`Tool ${name} executed successfully`);
|
|
123
|
+
return {
|
|
124
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return createErrorResponse(error);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
// 서버 시작 함수
|
|
132
|
+
async function runServer() {
|
|
133
|
+
try {
|
|
134
|
+
const transport = new StdioServerTransport();
|
|
135
|
+
// 서버 에러 핸들링
|
|
136
|
+
process.on("uncaughtException", (error) => {
|
|
137
|
+
console.error("Uncaught Exception:", error);
|
|
138
|
+
});
|
|
139
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
140
|
+
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
141
|
+
});
|
|
142
|
+
await server.connect(transport);
|
|
143
|
+
console.error("Naver Search MCP Server running on stdio");
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error("Fatal error running server:", error);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// 서버 시작
|
|
151
|
+
runServer().catch((error) => {
|
|
152
|
+
console.error("Fatal error running server:", error);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* NaverSearchClient - 네이버 API 서비스를 위한 싱글톤 클라이언트
|
|
4
|
+
* 검색, 데이터랩 API 요청 처리
|
|
5
|
+
*/
|
|
6
|
+
export class NaverSearchClient {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.searchBaseUrl = "https://openapi.naver.com/v1/search";
|
|
9
|
+
this.datalabBaseUrl = "https://openapi.naver.com/v1/datalab";
|
|
10
|
+
this.config = null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 싱글톤 인스턴스 반환
|
|
14
|
+
*/
|
|
15
|
+
static getInstance() {
|
|
16
|
+
if (!NaverSearchClient.instance) {
|
|
17
|
+
NaverSearchClient.instance = new NaverSearchClient();
|
|
18
|
+
}
|
|
19
|
+
return NaverSearchClient.instance;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* API 자격 증명으로 클라이언트 초기화
|
|
23
|
+
*/
|
|
24
|
+
initialize(config) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* API 요청에 필요한 헤더 생성
|
|
29
|
+
* @throws 클라이언트가 초기화되지 않은 경우 에러 발생
|
|
30
|
+
*/
|
|
31
|
+
getHeaders(contentType = "application/json") {
|
|
32
|
+
if (!this.config) {
|
|
33
|
+
throw new Error("NaverSearchClient is not initialized. Please call initialize() first.");
|
|
34
|
+
}
|
|
35
|
+
const headers = {
|
|
36
|
+
"X-Naver-Client-Id": this.config.clientId,
|
|
37
|
+
"X-Naver-Client-Secret": this.config.clientSecret,
|
|
38
|
+
"Content-Type": contentType,
|
|
39
|
+
};
|
|
40
|
+
return { headers };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 모든 검색 유형을 지원하는 일반 검색 메서드
|
|
44
|
+
*/
|
|
45
|
+
async search(params) {
|
|
46
|
+
const { type, ...searchParams } = params;
|
|
47
|
+
const response = await axios.get(`${this.searchBaseUrl}/${type}`, {
|
|
48
|
+
params: searchParams,
|
|
49
|
+
...this.getHeaders(),
|
|
50
|
+
});
|
|
51
|
+
return response.data;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 전문자료 검색 메서드
|
|
55
|
+
*/
|
|
56
|
+
async searchAcademic(params) {
|
|
57
|
+
return this.search({ type: "doc", ...params });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 지역 검색 메서드
|
|
61
|
+
*/
|
|
62
|
+
async searchLocal(params) {
|
|
63
|
+
const response = await axios.get(`${this.searchBaseUrl}/local`, {
|
|
64
|
+
params: { ...params },
|
|
65
|
+
...this.getHeaders(),
|
|
66
|
+
});
|
|
67
|
+
return response.data;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 검색어 트렌드 분석 메서드
|
|
71
|
+
*/
|
|
72
|
+
async searchTrend(params) {
|
|
73
|
+
return this.post("datalab", "/search", params);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 쇼핑 카테고리 트렌드 분석 메서드
|
|
77
|
+
*/
|
|
78
|
+
async datalabShoppingCategory(params) {
|
|
79
|
+
return this.post("datalab", "/shopping/categories", params);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 쇼핑 기기별 트렌드 분석 메서드
|
|
83
|
+
*/
|
|
84
|
+
async datalabShoppingByDevice(params) {
|
|
85
|
+
return this.post("datalab", "/shopping/category/device", params);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 쇼핑 성별 트렌드 분석 메서드
|
|
89
|
+
*/
|
|
90
|
+
async datalabShoppingByGender(params) {
|
|
91
|
+
return this.post("datalab", "/shopping/category/gender", params);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 쇼핑 연령별 트렌드 분석 메서드
|
|
95
|
+
*/
|
|
96
|
+
async datalabShoppingByAge(params) {
|
|
97
|
+
return this.post("datalab", "/shopping/category/age", params);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 쇼핑 키워드 트렌드 분석 메서드
|
|
101
|
+
*/
|
|
102
|
+
async datalabShoppingKeywords(params) {
|
|
103
|
+
return this.post("datalab", "/shopping/category/keywords", params);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 쇼핑 키워드 기기별 트렌드 분석 메서드
|
|
107
|
+
*/
|
|
108
|
+
async datalabShoppingKeywordByDevice(params) {
|
|
109
|
+
return this.post("datalab", "/shopping/category/keyword/device", params);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 쇼핑 키워드 성별 트렌드 분석 메서드
|
|
113
|
+
*/
|
|
114
|
+
async datalabShoppingKeywordByGender(params) {
|
|
115
|
+
return this.post("datalab", "/shopping/category/keyword/gender", params);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 쇼핑 키워드 연령별 트렌드 분석 메서드
|
|
119
|
+
*/
|
|
120
|
+
async datalabShoppingKeywordByAge(params) {
|
|
121
|
+
return this.post("datalab", "/shopping/category/keyword/age", params);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* POST 요청 처리 헬퍼 메서드
|
|
125
|
+
* @param apiType - API 유형 (search, datalab)
|
|
126
|
+
* @param endpoint - API 엔드포인트
|
|
127
|
+
* @param data - 요청 데이터
|
|
128
|
+
*/
|
|
129
|
+
async post(apiType, endpoint, data) {
|
|
130
|
+
if (!this.config) {
|
|
131
|
+
throw new Error("NaverSearchClient is not initialized. Please call initialize() first.");
|
|
132
|
+
}
|
|
133
|
+
const baseUrl = {
|
|
134
|
+
search: this.searchBaseUrl,
|
|
135
|
+
datalab: this.datalabBaseUrl,
|
|
136
|
+
}[apiType];
|
|
137
|
+
try {
|
|
138
|
+
const headers = {
|
|
139
|
+
"X-Naver-Client-Id": this.config.clientId,
|
|
140
|
+
"X-Naver-Client-Secret": this.config.clientSecret,
|
|
141
|
+
};
|
|
142
|
+
const response = await axios.post(`${baseUrl}${endpoint}`, data, {
|
|
143
|
+
headers,
|
|
144
|
+
});
|
|
145
|
+
return response.data;
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (axios.isAxiosError(error)) {
|
|
149
|
+
throw new Error(`Naver API Error: ${error.response?.data?.errorMessage || error.message}`);
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
NaverSearchClient.instance = null;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// 기본 DataLab 스키마
|
|
3
|
+
export const DatalabBaseSchema = z.object({
|
|
4
|
+
startDate: z.string().describe("Start date (yyyy-mm-dd)"),
|
|
5
|
+
endDate: z.string().describe("End date (yyyy-mm-dd)"),
|
|
6
|
+
timeUnit: z.enum(["date", "week", "month"]).describe("Time unit"),
|
|
7
|
+
});
|
|
8
|
+
// 검색어 트렌드 스키마
|
|
9
|
+
export const DatalabSearchSchema = DatalabBaseSchema.extend({
|
|
10
|
+
keywordGroups: z
|
|
11
|
+
.array(z.object({
|
|
12
|
+
groupName: z.string().describe("Group name"),
|
|
13
|
+
keywords: z.array(z.string()).describe("List of keywords"),
|
|
14
|
+
}))
|
|
15
|
+
.describe("Keyword groups"),
|
|
16
|
+
});
|
|
17
|
+
// 쇼핑 카테고리 스키마
|
|
18
|
+
export const DatalabShoppingSchema = DatalabBaseSchema.extend({
|
|
19
|
+
category: z
|
|
20
|
+
.array(z.object({
|
|
21
|
+
name: z.string().describe("Category name"),
|
|
22
|
+
param: z.array(z.string()).describe("Category codes"),
|
|
23
|
+
}))
|
|
24
|
+
.describe("Array of category name and code pairs"),
|
|
25
|
+
});
|
|
26
|
+
// 기기별 트렌드 스키마
|
|
27
|
+
export const DatalabShoppingDeviceSchema = DatalabBaseSchema.extend({
|
|
28
|
+
category: z.string().describe("Category code"),
|
|
29
|
+
device: z.enum(["pc", "mo"]).describe("Device type"),
|
|
30
|
+
});
|
|
31
|
+
// 성별 트렌드 스키마
|
|
32
|
+
export const DatalabShoppingGenderSchema = DatalabBaseSchema.extend({
|
|
33
|
+
category: z.string().describe("Category code"),
|
|
34
|
+
gender: z.enum(["f", "m"]).describe("Gender"),
|
|
35
|
+
});
|
|
36
|
+
// 연령별 트렌드 스키마
|
|
37
|
+
export const DatalabShoppingAgeSchema = DatalabBaseSchema.extend({
|
|
38
|
+
category: z.string().describe("Category code"),
|
|
39
|
+
ages: z
|
|
40
|
+
.array(z.enum(["10", "20", "30", "40", "50", "60"]))
|
|
41
|
+
.describe("Age groups"),
|
|
42
|
+
});
|
|
43
|
+
// 키워드 트렌드 스키마
|
|
44
|
+
export const DatalabShoppingKeywordsSchema = DatalabBaseSchema.extend({
|
|
45
|
+
category: z.string().describe("Category code"),
|
|
46
|
+
keyword: z
|
|
47
|
+
.array(z.object({
|
|
48
|
+
name: z.string().describe("Keyword name"),
|
|
49
|
+
param: z.array(z.string()).describe("Keyword values"),
|
|
50
|
+
}))
|
|
51
|
+
.describe("Array of keyword name and value pairs"),
|
|
52
|
+
});
|
|
53
|
+
// 키워드 기기별 트렌드 스키마
|
|
54
|
+
export const DatalabShoppingKeywordDeviceSchema = DatalabBaseSchema.extend({
|
|
55
|
+
category: z.string().describe("Category code"),
|
|
56
|
+
keyword: z.string().describe("Search keyword"),
|
|
57
|
+
device: z.enum(["pc", "mo"]).describe("Device type"),
|
|
58
|
+
});
|
|
59
|
+
// 키워드 성별 트렌드 스키마
|
|
60
|
+
export const DatalabShoppingKeywordGenderSchema = DatalabBaseSchema.extend({
|
|
61
|
+
category: z.string().describe("Category code"),
|
|
62
|
+
keyword: z.string().describe("Search keyword"),
|
|
63
|
+
gender: z.enum(["f", "m"]).describe("Gender"),
|
|
64
|
+
});
|
|
65
|
+
// 키워드 연령별 트렌드 스키마
|
|
66
|
+
export const DatalabShoppingKeywordAgeSchema = DatalabBaseSchema.extend({
|
|
67
|
+
category: z.string().describe("Category code"),
|
|
68
|
+
keyword: z.string().describe("Search keyword"),
|
|
69
|
+
ages: z
|
|
70
|
+
.array(z.enum(["10", "20", "30", "40", "50", "60"]))
|
|
71
|
+
.describe("Age groups"),
|
|
72
|
+
});
|
|
73
|
+
// 카테고리 디바이스/성별/연령별 트렌드 스키마
|
|
74
|
+
export const DatalabShoppingCategoryDeviceSchema = DatalabBaseSchema.extend({
|
|
75
|
+
category: z
|
|
76
|
+
.array(z.object({
|
|
77
|
+
name: z.string().describe("Category name"),
|
|
78
|
+
param: z.array(z.string()).describe("Category codes"),
|
|
79
|
+
}))
|
|
80
|
+
.describe("Array of category name and code pairs"),
|
|
81
|
+
device: z.enum(["pc", "mo"]).optional().describe("Device type"),
|
|
82
|
+
gender: z.enum(["f", "m"]).optional().describe("Gender"),
|
|
83
|
+
ages: z
|
|
84
|
+
.array(z.enum(["10", "20", "30", "40", "50", "60"]))
|
|
85
|
+
.optional()
|
|
86
|
+
.describe("Age groups"),
|
|
87
|
+
});
|
|
88
|
+
// 키워드 디바이스/성별/연령별 트렌드 스키마
|
|
89
|
+
export const DatalabShoppingKeywordTrendSchema = DatalabBaseSchema.extend({
|
|
90
|
+
category: z.string().describe("Category code"),
|
|
91
|
+
keyword: z
|
|
92
|
+
.array(z.object({
|
|
93
|
+
name: z.string().describe("Keyword name"),
|
|
94
|
+
param: z.array(z.string()).describe("Keyword values"),
|
|
95
|
+
}))
|
|
96
|
+
.describe("Array of keyword name and value pairs"),
|
|
97
|
+
device: z.enum(["pc", "mo"]).optional().describe("Device type"),
|
|
98
|
+
gender: z.enum(["f", "m"]).optional().describe("Gender"),
|
|
99
|
+
ages: z
|
|
100
|
+
.array(z.enum(["10", "20", "30", "40", "50", "60"]))
|
|
101
|
+
.optional()
|
|
102
|
+
.describe("Age groups"),
|
|
103
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// 기본 검색 파라미터 스키마
|
|
3
|
+
export const SearchArgsSchema = z.object({
|
|
4
|
+
query: z.string().describe("Search query"),
|
|
5
|
+
display: z
|
|
6
|
+
.number()
|
|
7
|
+
.optional()
|
|
8
|
+
.describe("Number of results to display (default: 10)"),
|
|
9
|
+
start: z
|
|
10
|
+
.number()
|
|
11
|
+
.optional()
|
|
12
|
+
.describe("Start position of search results (default: 1)"),
|
|
13
|
+
sort: z
|
|
14
|
+
.enum(["sim", "date"])
|
|
15
|
+
.optional()
|
|
16
|
+
.describe("Sort method (sim: similarity, date: date)"),
|
|
17
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
+
import { DatalabSearchSchema, DatalabShoppingSchema, DatalabShoppingDeviceSchema, DatalabShoppingGenderSchema, DatalabShoppingAgeSchema, DatalabShoppingKeywordsSchema, DatalabShoppingKeywordDeviceSchema, DatalabShoppingKeywordGenderSchema, DatalabShoppingKeywordAgeSchema } from "../schemas/datalab.schemas.js";
|
|
3
|
+
/**
|
|
4
|
+
* 데이터랩 관련 도구 정의
|
|
5
|
+
*/
|
|
6
|
+
export const datalabTools = [
|
|
7
|
+
{
|
|
8
|
+
name: "datalab_search",
|
|
9
|
+
description: "Perform a trend analysis on Naver search keywords. (네이버 검색어 트렌드 분석)",
|
|
10
|
+
inputSchema: zodToJsonSchema(DatalabSearchSchema),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "datalab_shopping_category",
|
|
14
|
+
description: "Perform a trend analysis on Naver Shopping category. (네이버 쇼핑 카테고리별 트렌드 분석)",
|
|
15
|
+
inputSchema: zodToJsonSchema(DatalabShoppingSchema),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "datalab_shopping_by_device",
|
|
19
|
+
description: "Perform a trend analysis on Naver Shopping by device. (네이버 쇼핑 기기별 트렌드 분석)",
|
|
20
|
+
inputSchema: zodToJsonSchema(DatalabShoppingDeviceSchema.pick({
|
|
21
|
+
startDate: true,
|
|
22
|
+
endDate: true,
|
|
23
|
+
timeUnit: true,
|
|
24
|
+
category: true,
|
|
25
|
+
device: true,
|
|
26
|
+
})),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "datalab_shopping_by_gender",
|
|
30
|
+
description: "Perform a trend analysis on Naver Shopping by gender. (네이버 쇼핑 성별 트렌드 분석)",
|
|
31
|
+
inputSchema: zodToJsonSchema(DatalabShoppingGenderSchema.pick({
|
|
32
|
+
startDate: true,
|
|
33
|
+
endDate: true,
|
|
34
|
+
timeUnit: true,
|
|
35
|
+
category: true,
|
|
36
|
+
gender: true,
|
|
37
|
+
})),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "datalab_shopping_by_age",
|
|
41
|
+
description: "Perform a trend analysis on Naver Shopping by age. (네이버 쇼핑 연령별 트렌드 분석)",
|
|
42
|
+
inputSchema: zodToJsonSchema(DatalabShoppingAgeSchema.pick({
|
|
43
|
+
startDate: true,
|
|
44
|
+
endDate: true,
|
|
45
|
+
timeUnit: true,
|
|
46
|
+
category: true,
|
|
47
|
+
ages: true,
|
|
48
|
+
})),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "datalab_shopping_keywords",
|
|
52
|
+
description: "Perform a trend analysis on Naver Shopping keywords. (네이버 쇼핑 키워드별 트렌드 분석)",
|
|
53
|
+
inputSchema: zodToJsonSchema(DatalabShoppingKeywordsSchema),
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "datalab_shopping_keyword_by_device",
|
|
57
|
+
description: "Perform a trend analysis on Naver Shopping keywords by device. (네이버 쇼핑 키워드 기기별 트렌드 분석)",
|
|
58
|
+
inputSchema: zodToJsonSchema(DatalabShoppingKeywordDeviceSchema),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "datalab_shopping_keyword_by_gender",
|
|
62
|
+
description: "Perform a trend analysis on Naver Shopping keywords by gender. (네이버 쇼핑 키워드 성별 트렌드 분석)",
|
|
63
|
+
inputSchema: zodToJsonSchema(DatalabShoppingKeywordGenderSchema),
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "datalab_shopping_keyword_by_age",
|
|
67
|
+
description: "Perform a trend analysis on Naver Shopping keywords by age. (네이버 쇼핑 키워드 연령별 트렌드 분석)",
|
|
68
|
+
inputSchema: zodToJsonSchema(DatalabShoppingKeywordAgeSchema),
|
|
69
|
+
},
|
|
70
|
+
];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
+
import { SearchArgsSchema } from "../schemas/search.schemas.js";
|
|
3
|
+
import { NaverLocalSearchParamsSchema } from "../types/naver-search.types.js";
|
|
4
|
+
/**
|
|
5
|
+
* 검색 관련 도구 정의
|
|
6
|
+
*/
|
|
7
|
+
export const searchTools = [
|
|
8
|
+
{
|
|
9
|
+
name: "search_webkr",
|
|
10
|
+
description: "Perform a search on Naver Web Documents. (네이버 웹문서 검색)",
|
|
11
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "search_news",
|
|
15
|
+
description: "Perform a search on Naver News. (네이버 뉴스 검색)",
|
|
16
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "search_blog",
|
|
20
|
+
description: "Perform a search on Naver Blog. (네이버 블로그 검색)",
|
|
21
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "search_shop",
|
|
25
|
+
description: "Perform a search on Naver Shopping. (네이버 쇼핑 검색)",
|
|
26
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "search_image",
|
|
30
|
+
description: "Perform a search on Naver Image. (네이버 이미지 검색)",
|
|
31
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "search_kin",
|
|
35
|
+
description: "Perform a search on Naver KnowledgeiN. (네이버 지식iN 검색)",
|
|
36
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "search_book",
|
|
40
|
+
description: "Perform a search on Naver Book. (네이버 책 검색)",
|
|
41
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "search_encyc",
|
|
45
|
+
description: "Perform a search on Naver Encyclopedia. (네이버 지식백과 검색)",
|
|
46
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "search_academic",
|
|
50
|
+
description: "Perform a search on Naver Academic. (네이버 전문자료 검색)",
|
|
51
|
+
inputSchema: zodToJsonSchema(SearchArgsSchema),
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "search_local",
|
|
55
|
+
description: "Perform a search on Naver Local. (네이버 지역 검색)",
|
|
56
|
+
inputSchema: zodToJsonSchema(NaverLocalSearchParamsSchema),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const NaverSearchTypeSchema = z.enum([
|
|
3
|
+
"news",
|
|
4
|
+
"encyc",
|
|
5
|
+
"blog",
|
|
6
|
+
"shop",
|
|
7
|
+
"webkr",
|
|
8
|
+
"image",
|
|
9
|
+
"doc",
|
|
10
|
+
"kin",
|
|
11
|
+
"book",
|
|
12
|
+
"cafearticle",
|
|
13
|
+
"local",
|
|
14
|
+
]);
|
|
15
|
+
export const NaverSearchParamsSchema = z.object({
|
|
16
|
+
query: z.string().describe("Search query"),
|
|
17
|
+
display: z
|
|
18
|
+
.number()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("Number of results to display (default: 10)"),
|
|
21
|
+
start: z
|
|
22
|
+
.number()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Start position of search results (default: 1)"),
|
|
25
|
+
sort: z
|
|
26
|
+
.enum(["sim", "date"])
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Sort method (sim: similarity, date: chronological)"),
|
|
29
|
+
});
|
|
30
|
+
export const NaverSearchConfigSchema = z.object({
|
|
31
|
+
clientId: z.string().describe("Client ID issued by Naver Developer Center"),
|
|
32
|
+
clientSecret: z
|
|
33
|
+
.string()
|
|
34
|
+
.describe("Client Secret issued by Naver Developer Center"),
|
|
35
|
+
});
|
|
36
|
+
// 전문자료 검색 파라미터 스키마
|
|
37
|
+
export const NaverDocumentSearchParamsSchema = z.object({
|
|
38
|
+
query: z.string().describe("Search query"),
|
|
39
|
+
display: z
|
|
40
|
+
.number()
|
|
41
|
+
.optional()
|
|
42
|
+
.describe("Number of results to display (default: 10, max: 100)"),
|
|
43
|
+
start: z
|
|
44
|
+
.number()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Start position of search results (default: 1, max: 1000)"),
|
|
47
|
+
});
|
|
48
|
+
// 지역 검색 파라미터 스키마
|
|
49
|
+
export const NaverLocalSearchParamsSchema = NaverSearchParamsSchema.extend({
|
|
50
|
+
sort: z.enum(["random", "comment"])
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Sort method (random: accuracy, comment: review count)"),
|
|
53
|
+
display: z
|
|
54
|
+
.number()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("Number of results to display (default: 1, max: 5)"),
|
|
57
|
+
start: z
|
|
58
|
+
.number()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe("Start position of search results (default: 1, max: 1)"),
|
|
61
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import sharp from "sharp";
|
|
2
|
+
export class ImageProcessor {
|
|
3
|
+
/**
|
|
4
|
+
* base64 이미지를 압축하여 Buffer로 반환
|
|
5
|
+
* @param base64Image base64로 인코딩된 이미지
|
|
6
|
+
* @returns 압축된 이미지 Buffer
|
|
7
|
+
*/
|
|
8
|
+
static async compressImage(base64Image) {
|
|
9
|
+
const imageBuffer = Buffer.from(base64Image, "base64");
|
|
10
|
+
// 이미지 크기가 2MB 이하면 그대로 반환
|
|
11
|
+
if (imageBuffer.length <= this.MAX_SIZE) {
|
|
12
|
+
return imageBuffer;
|
|
13
|
+
}
|
|
14
|
+
// 이미지 메타데이터 가져오기
|
|
15
|
+
const metadata = await sharp(imageBuffer).metadata();
|
|
16
|
+
// 압축 품질 계산 (2MB를 기준으로 비율 계산)
|
|
17
|
+
const quality = Math.floor((this.MAX_SIZE / imageBuffer.length) * 100);
|
|
18
|
+
// 이미지 크기 조절 계수 계산
|
|
19
|
+
const scale = Math.sqrt(this.MAX_SIZE / imageBuffer.length);
|
|
20
|
+
const width = Math.floor((metadata.width || 1000) * scale);
|
|
21
|
+
const height = Math.floor((metadata.height || 1000) * scale);
|
|
22
|
+
// 이미지 압축
|
|
23
|
+
const compressedBuffer = await sharp(imageBuffer)
|
|
24
|
+
.resize(width, height, {
|
|
25
|
+
fit: "inside",
|
|
26
|
+
withoutEnlargement: true,
|
|
27
|
+
})
|
|
28
|
+
.jpeg({
|
|
29
|
+
quality: Math.max(quality, 60), // 최소 품질 60으로 제한
|
|
30
|
+
progressive: true,
|
|
31
|
+
})
|
|
32
|
+
.toBuffer();
|
|
33
|
+
// 압축 후에도 2MB를 초과하면 더 강하게 압축
|
|
34
|
+
if (compressedBuffer.length > this.MAX_SIZE) {
|
|
35
|
+
return await sharp(compressedBuffer)
|
|
36
|
+
.jpeg({
|
|
37
|
+
quality: 60,
|
|
38
|
+
progressive: true,
|
|
39
|
+
})
|
|
40
|
+
.toBuffer();
|
|
41
|
+
}
|
|
42
|
+
return compressedBuffer;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 이미지 크기 확인
|
|
46
|
+
* @param imageBuffer 이미지 버퍼
|
|
47
|
+
* @returns 이미지 크기가 2MB를 초과하는지 여부
|
|
48
|
+
*/
|
|
49
|
+
static isOversize(imageBuffer) {
|
|
50
|
+
return imageBuffer.length > this.MAX_SIZE;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 이미지 메타데이터 확인
|
|
54
|
+
* @param imageBuffer 이미지 버퍼
|
|
55
|
+
* @returns 이미지 메타데이터
|
|
56
|
+
*/
|
|
57
|
+
static async getMetadata(imageBuffer) {
|
|
58
|
+
return await sharp(imageBuffer).metadata();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
ImageProcessor.MAX_SIZE = 2 * 1024 * 1024; // 2MB
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@isnow890/naver-search-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Naver Search MCP Server",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prebuild": "shx rm -rf dist",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepare": "npm run build",
|
|
14
|
+
"watch": "tsc --watch",
|
|
15
|
+
"start": "node dist/src/index.js"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@modelcontextprotocol/sdk": "0.5.0",
|
|
22
|
+
"axios": "^1.6.7",
|
|
23
|
+
"zod": "^3.22.4",
|
|
24
|
+
"zod-to-json-schema": "^3.23.5",
|
|
25
|
+
"sharp": "^0.33.2",
|
|
26
|
+
"dotenv": "^16.4.5"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^22",
|
|
30
|
+
"shx": "^0.3.4",
|
|
31
|
+
"typescript": "^5.3.3"
|
|
32
|
+
},
|
|
33
|
+
"author": "isnow890",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"bin": {
|
|
36
|
+
"naver-search-mcp": "dist/src/index.js"
|
|
37
|
+
},
|
|
38
|
+
"type": "module"
|
|
39
|
+
}
|