@isnow890/naver-search-mcp 1.0.14 → 1.0.18

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 CHANGED
@@ -1,21 +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.
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 CHANGED
@@ -1,184 +1,187 @@
1
- # Naver Search MCP Server
2
-
3
- [![한국어](https://img.shields.io/badge/한국어-README-yellow)](README-ko.md)
4
- [![smithery badge](https://smithery.ai/badge/@isnow890/naver-search-mcp)](https://smithery.ai/server/@isnow890/naver-search-mcp)
5
- [![MCP.so](https://img.shields.io/badge/MCP.so-Naver%20Search%20MCP-blue)](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 @isnow890/naver-search-mcp
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
- ## Claude 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", "@isnow890/naver-search-mcp"],
124
- "env": {
125
- "NAVER_CLIENT_ID": "your_client_id",
126
- "NAVER_CLIENT_SECRET": "your_client_secret"
127
- }
128
- }
129
- }
130
- }
131
- ```
132
-
133
- ## Cursor AI Configuration
134
-
135
- Add to `mcp.json`:
136
-
137
- ```json
138
- {
139
- "mcpServers": {
140
- "naver-search": {
141
- "command": "npx",
142
- "args": ["-y", "@isnow890/naver-search-mcp"],
143
- "env": {
144
- "NAVER_CLIENT_ID": "your_client_id",
145
- "NAVER_CLIENT_SECRET": "your_client_secret"
146
- }
147
- }
148
- }
149
- }
150
- ```
151
-
152
- For Docker:
153
-
154
- ```json
155
- {
156
- "mcpServers": {
157
- "naver-search": {
158
- "command": "docker",
159
- "args": [
160
- "run",
161
- "-i",
162
- "--rm",
163
- "-e",
164
- "NAVER_CLIENT_ID=your_client_id",
165
- "-e",
166
- "NAVER_CLIENT_SECRET=your_client_secret",
167
- "mcp/naver-search"
168
- ]
169
- }
170
- }
171
- }
172
- ```
173
-
174
- ## Build
175
-
176
- Docker build:
177
-
178
- ```bash
179
- docker build -t mcp/naver-search .
180
- ```
181
-
182
- ## License
183
-
184
- MIT License
1
+ # Naver Search MCP Server
2
+
3
+ [![한국어](https://img.shields.io/badge/한국어-README-yellow)](README-ko.md)
4
+ [![smithery badge](https://smithery.ai/badge/@isnow890/naver-search-mcp)](https://smithery.ai/server/@isnow890/naver-search-mcp)
5
+ [![MCP.so](https://img.shields.io/badge/MCP.so-Naver%20Search%20MCP-blue)](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
+ #### Version History
10
+
11
+ ###### 1.0.2 (2025-04-26)
12
+
13
+ - README updated: cafe article search tool and version history section improved
14
+
15
+ ###### 1.0.1 (2025-04-26)
16
+
17
+ - Cafe article search feature added
18
+ - Shopping category info added to zod
19
+ - Source code refactored
20
+
21
+ ###### 1.0.0 (2025-04-08)
22
+
23
+ - Initial release
24
+
25
+ #### Information
26
+
27
+ **If you want to install the MCP via npm, do NOT use @mseep/server-naver-search (https://www.npmjs.com/package/@mseep/server-naver-search). That package is a copy of my work and was published without my permission. The npx version of that package is also broken and will not work properly. Please use this official package instead.**
28
+
29
+ #### Prerequisites
30
+
31
+ - Naver Developers API Key (Client ID and Secret)
32
+ - Node.js 18 or higher
33
+ - NPM 8 or higher
34
+ - Docker (optional, for container deployment)
35
+
36
+ #### Getting API Keys
37
+
38
+ 1. Visit [Naver Developers](https://developers.naver.com/apps/#/register)
39
+ 2. Click "Register Application"
40
+ 3. Enter application name and select ALL of the following APIs:
41
+ - Search (for blog, news, book search, etc.)
42
+ - DataLab (Search Trends)
43
+ - DataLab (Shopping Insight)
44
+ 4. Set the obtained Client ID and Client Secret as environment variables
45
+
46
+ ## Tool Details
47
+
48
+ ### Available tools:
49
+
50
+ - **search_webkr**: Search Naver web documents
51
+ - **search_news**: Search Naver news
52
+ - **search_blog**: Search Naver blogs
53
+ - **search_cafearticle**: Search Naver cafe articles
54
+ - **search_shop**: Search Naver shopping
55
+ - **search_image**: Search Naver images
56
+ - **search_kin**: Search Naver KnowledgeiN
57
+ - **search_book**: Search Naver books
58
+ - **search_encyc**: Search Naver encyclopedia
59
+ - **search_academic**: Search Naver academic papers
60
+ - **search_local**: Search Naver local places
61
+ - **datalab_search**: Analyze search term trends
62
+ - **datalab_shopping_category**: Analyze shopping category trends
63
+ - **datalab_shopping_by_device**: Analyze shopping trends by device
64
+ - **datalab_shopping_by_gender**: Analyze shopping trends by gender
65
+ - **datalab_shopping_by_age**: Analyze shopping trends by age group
66
+ - **datalab_shopping_keywords**: Analyze shopping keyword trends
67
+ - **datalab_shopping_keyword_by_device**: Analyze shopping keyword trends by device
68
+ - **datalab_shopping_keyword_by_gender**: Analyze shopping keyword trends by gender
69
+ - **datalab_shopping_keyword_by_age**: Analyze shopping keyword trends by age group
70
+
71
+ ## Installation
72
+
73
+ ### Option 1: Quick Install via Smithery (Recommended)
74
+
75
+ To install Naver Search MCP Server automatically via Smithery, use one of these commands based on your AI client:
76
+
77
+ For Claude Desktop:
78
+
79
+ ```bash
80
+ npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client claude
81
+ ```
82
+
83
+ For Cursor:
84
+
85
+ ```bash
86
+ npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client cursor
87
+ ```
88
+
89
+ For Windsurf:
90
+
91
+ ```bash
92
+ npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client windsurf
93
+ ```
94
+
95
+ For Cline:
96
+
97
+ ```bash
98
+ npx -y @smithery/cli@latest install @isnow890/naver-search-mcp --client cline
99
+ ```
100
+
101
+ The installer will prompt you for:
102
+
103
+ - NAVER_CLIENT_ID
104
+ - NAVER_CLIENT_SECRET
105
+
106
+ ### Option 2: Manual Installation
107
+
108
+ #### Environment Variables
109
+
110
+ ```bash
111
+ # Windows
112
+ set NAVER_CLIENT_ID=your_client_id
113
+ set NAVER_CLIENT_SECRET=your_client_secret
114
+
115
+ # Linux/Mac
116
+ export NAVER_CLIENT_ID=your_client_id
117
+ export NAVER_CLIENT_SECRET=your_client_secret
118
+ ```
119
+
120
+ #### Run with NPX
121
+
122
+ ```bash
123
+ npx @modelcontextprotocol/server-naver-search
124
+ ```
125
+
126
+ #### Run with Docker
127
+
128
+ ```bash
129
+ docker run -i --rm \
130
+ -e NAVER_CLIENT_ID=your_client_id \
131
+ -e NAVER_CLIENT_SECRET=your_client_secret \
132
+ mcp/naver-search
133
+ ```
134
+
135
+ ## Cursor Desktop Configuration
136
+
137
+ Add to `claude_desktop_config.json`:
138
+
139
+ ```json
140
+ {
141
+ "mcpServers": {
142
+ "naver-search": {
143
+ "command": "npx",
144
+ "args": ["-y", "@modelcontextprotocol/server-naver-search"],
145
+ "env": {
146
+ "NAVER_CLIENT_ID": "your_client_id",
147
+ "NAVER_CLIENT_SECRET": "your_client_secret"
148
+ }
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ For Docker:
155
+
156
+ ```json
157
+ {
158
+ "mcpServers": {
159
+ "naver-search": {
160
+ "command": "docker",
161
+ "args": [
162
+ "run",
163
+ "-i",
164
+ "--rm",
165
+ "-e",
166
+ "NAVER_CLIENT_ID=your_client_id",
167
+ "-e",
168
+ "NAVER_CLIENT_SECRET=your_client_secret",
169
+ "mcp/naver-search"
170
+ ]
171
+ }
172
+ }
173
+ }
174
+ ```
175
+ ## Build
176
+
177
+ Docker build:
178
+
179
+ ```bash
180
+ docker build -t mcp/naver-search .
181
+ ```
182
+
183
+
184
+
185
+ ## License
186
+
187
+ MIT License
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@isnow890/naver-search-mcp",
3
+ "version": "1.0.18",
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": "1.10.2",
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
+ }
@@ -0,0 +1,30 @@
1
+ import axios from "axios";
2
+ export class NaverApiCoreClient {
3
+ constructor() {
4
+ this.searchBaseUrl = "https://openapi.naver.com/v1/search";
5
+ this.datalabBaseUrl = "https://openapi.naver.com/v1/datalab";
6
+ this.config = null;
7
+ }
8
+ initialize(config) {
9
+ this.config = config;
10
+ }
11
+ getHeaders(contentType = "application/json") {
12
+ if (!this.config)
13
+ throw new Error("NaverApiCoreClient is not initialized.");
14
+ return {
15
+ headers: {
16
+ "X-Naver-Client-Id": this.config.clientId,
17
+ "X-Naver-Client-Secret": this.config.clientSecret,
18
+ "Content-Type": contentType,
19
+ },
20
+ };
21
+ }
22
+ async get(url, params) {
23
+ const response = await axios.get(url, { params, ...this.getHeaders() });
24
+ return response.data;
25
+ }
26
+ async post(url, data) {
27
+ const response = await axios.post(url, data, this.getHeaders());
28
+ return response.data;
29
+ }
30
+ }
@@ -0,0 +1,100 @@
1
+ import { NaverApiCoreClient } from "./naver-api-core.client.js";
2
+ /**
3
+ * NaverSearchClient - 네이버 API 서비스를 위한 싱글톤 클라이언트
4
+ * 검색, 데이터랩 API 요청 처리
5
+ */
6
+ export class NaverSearchClient extends NaverApiCoreClient {
7
+ constructor() {
8
+ super();
9
+ }
10
+ /**
11
+ * 싱글톤 인스턴스 반환
12
+ */
13
+ static getInstance() {
14
+ if (!NaverSearchClient.instance) {
15
+ NaverSearchClient.instance = new NaverSearchClient();
16
+ }
17
+ return NaverSearchClient.instance;
18
+ }
19
+ /**
20
+ * API 자격 증명으로 클라이언트 초기화
21
+ */
22
+ initialize(config) {
23
+ this.config = config;
24
+ }
25
+ /**
26
+ * 네이버 검색 API 호출 (type별로)
27
+ * @param type 검색 타입(카테고리)
28
+ * @param params 검색 파라미터
29
+ */
30
+ async search(type, params) {
31
+ return this.get(`${this.searchBaseUrl}/${type}`, params);
32
+ }
33
+ /**
34
+ * 전문자료 검색 메서드
35
+ */
36
+ async searchAcademic(params) {
37
+ return this.get(`${this.searchBaseUrl}/doc`, params);
38
+ }
39
+ /**
40
+ * 지역 검색 메서드
41
+ */
42
+ async searchLocal(params) {
43
+ return this.get(`${this.searchBaseUrl}/local`, params);
44
+ }
45
+ /**
46
+ * 검색어 트렌드 분석 메서드
47
+ */
48
+ async searchTrend(params) {
49
+ return this.post(`${this.datalabBaseUrl}/search`, params);
50
+ }
51
+ /**
52
+ * 쇼핑 카테고리 트렌드 분석 메서드
53
+ */
54
+ async datalabShoppingCategory(params) {
55
+ return this.post(`${this.datalabBaseUrl}/shopping/categories`, params);
56
+ }
57
+ /**
58
+ * 쇼핑 기기별 트렌드 분석 메서드
59
+ */
60
+ async datalabShoppingByDevice(params) {
61
+ return this.post(`${this.datalabBaseUrl}/shopping/category/device`, params);
62
+ }
63
+ /**
64
+ * 쇼핑 성별 트렌드 분석 메서드
65
+ */
66
+ async datalabShoppingByGender(params) {
67
+ return this.post(`${this.datalabBaseUrl}/shopping/category/gender`, params);
68
+ }
69
+ /**
70
+ * 쇼핑 연령별 트렌드 분석 메서드
71
+ */
72
+ async datalabShoppingByAge(params) {
73
+ return this.post(`${this.datalabBaseUrl}/shopping/category/age`, params);
74
+ }
75
+ /**
76
+ * 쇼핑 키워드 트렌드 분석 메서드
77
+ */
78
+ async datalabShoppingKeywords(params) {
79
+ return this.post(`${this.datalabBaseUrl}/shopping/category/keywords`, params);
80
+ }
81
+ /**
82
+ * 쇼핑 키워드 기기별 트렌드 분석 메서드
83
+ */
84
+ async datalabShoppingKeywordByDevice(params) {
85
+ return this.post(`${this.datalabBaseUrl}/shopping/category/keyword/device`, params);
86
+ }
87
+ /**
88
+ * 쇼핑 키워드 성별 트렌드 분석 메서드
89
+ */
90
+ async datalabShoppingKeywordByGender(params) {
91
+ return this.post(`${this.datalabBaseUrl}/shopping/category/keyword/gender`, params);
92
+ }
93
+ /**
94
+ * 쇼핑 키워드 연령별 트렌드 분석 메서드
95
+ */
96
+ async datalabShoppingKeywordByAge(params) {
97
+ return this.post(`${this.datalabBaseUrl}/shopping/category/keyword/age`, params);
98
+ }
99
+ }
100
+ NaverSearchClient.instance = null;
@@ -1,20 +1,42 @@
1
- import { NaverSearchClient } from "../naver-search.client.js";
2
- // 클라이언트 인스턴스
1
+ import { NaverSearchClient } from "../clients/naver-search.client.js";
2
+ // 클라이언트 인스턴스 (싱글톤)
3
3
  const client = NaverSearchClient.getInstance();
4
+ /**
5
+ * 데이터랩 도구 핸들러 맵
6
+ * 각 도구 이름을 키로, 실행할 핸들러 함수를 값으로 가짐
7
+ * index.ts에서 도구 실행 분기 없이 바로 사용
8
+ */
9
+ export const datalabToolHandlers = {
10
+ datalab_search: (args) => handleSearchTrend(args), // 검색어 트렌드 분석
11
+ datalab_shopping_category: (args) => handleShoppingCategoryTrend(args), // 쇼핑 카테고리별 트렌드
12
+ datalab_shopping_by_device: (args) => handleShoppingByDeviceTrend(args), // 쇼핑 기기별 트렌드
13
+ datalab_shopping_by_gender: (args) => handleShoppingByGenderTrend(args), // 쇼핑 성별 트렌드
14
+ datalab_shopping_by_age: (args) => handleShoppingByAgeTrend(args), // 쇼핑 연령별 트렌드
15
+ datalab_shopping_keywords: (args) => handleShoppingKeywordsTrend(args), // 쇼핑 키워드 그룹 트렌드
16
+ datalab_shopping_keyword_by_device: (args) => handleShoppingKeywordByDeviceTrend(args), // 쇼핑 키워드 기기별 트렌드
17
+ datalab_shopping_keyword_by_gender: (args) => handleShoppingKeywordByGenderTrend(args), // 쇼핑 키워드 성별 트렌드
18
+ datalab_shopping_keyword_by_age: (args) => handleShoppingKeywordByAgeTrend(args), // 쇼핑 키워드 연령별 트렌드
19
+ };
4
20
  /**
5
21
  * 검색어 트렌드 핸들러
22
+ * 네이버 데이터랩 검색어 트렌드 분석 API 호출
23
+ * @param params DatalabSearch
6
24
  */
7
25
  export async function handleSearchTrend(params) {
8
26
  return client.searchTrend(params);
9
27
  }
10
28
  /**
11
29
  * 쇼핑 카테고리 트렌드 핸들러
30
+ * 네이버 데이터랩 쇼핑 카테고리별 트렌드 분석 API 호출
31
+ * @param params DatalabShopping
12
32
  */
13
33
  export async function handleShoppingCategoryTrend(params) {
14
34
  return client.datalabShoppingCategory(params);
15
35
  }
16
36
  /**
17
37
  * 쇼핑 기기별 트렌드 핸들러
38
+ * 네이버 데이터랩 쇼핑 기기별 트렌드 분석 API 호출
39
+ * @param params DatalabShoppingDevice
18
40
  */
19
41
  export async function handleShoppingByDeviceTrend(params) {
20
42
  return client.datalabShoppingByDevice({
@@ -27,6 +49,8 @@ export async function handleShoppingByDeviceTrend(params) {
27
49
  }
28
50
  /**
29
51
  * 쇼핑 성별 트렌드 핸들러
52
+ * 네이버 데이터랩 쇼핑 성별 트렌드 분석 API 호출
53
+ * @param params DatalabShoppingGender
30
54
  */
31
55
  export async function handleShoppingByGenderTrend(params) {
32
56
  return client.datalabShoppingByGender({
@@ -39,6 +63,8 @@ export async function handleShoppingByGenderTrend(params) {
39
63
  }
40
64
  /**
41
65
  * 쇼핑 연령별 트렌드 핸들러
66
+ * 네이버 데이터랩 쇼핑 연령별 트렌드 분석 API 호출
67
+ * @param params DatalabShoppingAge
42
68
  */
43
69
  export async function handleShoppingByAgeTrend(params) {
44
70
  return client.datalabShoppingByAge({
@@ -50,8 +76,9 @@ export async function handleShoppingByAgeTrend(params) {
50
76
  });
51
77
  }
52
78
  /**
53
- * 쇼핑 키워드 트렌드 핸들러
54
- * 복수 키워드 그룹을 지원합니다.
79
+ * 쇼핑 키워드 트렌드 핸들러 (복수 키워드 그룹 지원)
80
+ * 네이버 데이터랩 쇼핑 키워드 그룹 트렌드 분석 API 호출
81
+ * @param params DatalabShoppingKeywords
55
82
  */
56
83
  export async function handleShoppingKeywordsTrend(params) {
57
84
  // 키워드 배열을 네이버 API에 맞는 형식으로 변환
@@ -60,11 +87,13 @@ export async function handleShoppingKeywordsTrend(params) {
60
87
  endDate: params.endDate,
61
88
  timeUnit: params.timeUnit,
62
89
  category: params.category,
63
- keyword: params.keyword
90
+ keyword: params.keyword,
64
91
  });
65
92
  }
66
93
  /**
67
94
  * 쇼핑 키워드 기기별 트렌드 핸들러
95
+ * 네이버 데이터랩 쇼핑 키워드 기기별 트렌드 분석 API 호출
96
+ * @param params DatalabShoppingKeywordDevice
68
97
  */
69
98
  export async function handleShoppingKeywordByDeviceTrend(params) {
70
99
  return client.datalabShoppingKeywordByDevice({
@@ -78,6 +107,8 @@ export async function handleShoppingKeywordByDeviceTrend(params) {
78
107
  }
79
108
  /**
80
109
  * 쇼핑 키워드 성별 트렌드 핸들러
110
+ * 네이버 데이터랩 쇼핑 키워드 성별 트렌드 분석 API 호출
111
+ * @param params DatalabShoppingKeywordGender
81
112
  */
82
113
  export async function handleShoppingKeywordByGenderTrend(params) {
83
114
  return client.datalabShoppingKeywordByGender({
@@ -91,6 +122,8 @@ export async function handleShoppingKeywordByGenderTrend(params) {
91
122
  }
92
123
  /**
93
124
  * 쇼핑 키워드 연령별 트렌드 핸들러
125
+ * 네이버 데이터랩 쇼핑 키워드 연령별 트렌드 분석 API 호출
126
+ * @param params DatalabShoppingKeywordAge
94
127
  */
95
128
  export async function handleShoppingKeywordByAgeTrend(params) {
96
129
  return client.datalabShoppingKeywordByAge({
@@ -1,12 +1,20 @@
1
- import { NaverSearchClient } from "../naver-search.client.js";
1
+ import { NaverSearchClient } from "../clients/naver-search.client.js";
2
+ import { SearchArgsSchema } from "../schemas/search.schemas.js";
2
3
  // 클라이언트 인스턴스
3
4
  const client = NaverSearchClient.getInstance();
4
- /**
5
- * 기본 검색 핸들러
6
- */
7
- export async function handleSearch(params) {
8
- return client.search({ ...params });
9
- }
5
+ export const searchToolHandlers = {
6
+ search_webkr: (args) => handleWebKrSearch(SearchArgsSchema.parse(args)),
7
+ search_news: (args) => handleNewsSearch(SearchArgsSchema.parse(args)),
8
+ search_blog: (args) => handleBlogSearch(SearchArgsSchema.parse(args)),
9
+ search_shop: (args) => handleShopSearch(SearchArgsSchema.parse(args)),
10
+ search_image: (args) => handleImageSearch(SearchArgsSchema.parse(args)),
11
+ search_kin: (args) => handleKinSearch(SearchArgsSchema.parse(args)),
12
+ search_book: (args) => handleBookSearch(SearchArgsSchema.parse(args)),
13
+ search_encyc: (args) => handleEncycSearch(SearchArgsSchema.parse(args)),
14
+ search_academic: (args) => handleAcademicSearch(SearchArgsSchema.parse(args)),
15
+ search_local: (args) => handleLocalSearch(args),
16
+ search_cafearticle: (args) => handleCafeArticleSearch(args),
17
+ };
10
18
  /**
11
19
  * 전문자료 검색 핸들러
12
20
  */
@@ -17,25 +25,25 @@ export async function handleAcademicSearch(params) {
17
25
  * 도서 검색 핸들러
18
26
  */
19
27
  export async function handleBookSearch(params) {
20
- return client.search({ type: "book", ...params });
28
+ return client.search("book", params);
21
29
  }
22
30
  /**
23
31
  * 지식백과 검색 핸들러
24
32
  */
25
33
  export async function handleEncycSearch(params) {
26
- return client.search({ type: "encyc", ...params });
34
+ return client.search("encyc", params);
27
35
  }
28
36
  /**
29
37
  * 이미지 검색 핸들러
30
38
  */
31
39
  export async function handleImageSearch(params) {
32
- return client.search({ type: "image", ...params });
40
+ return client.search("image", params);
33
41
  }
34
42
  /**
35
43
  * 지식iN 검색 핸들러
36
44
  */
37
45
  export async function handleKinSearch(params) {
38
- return client.search({ type: "kin", ...params });
46
+ return client.search("kin", params);
39
47
  }
40
48
  /**
41
49
  * 지역 검색 핸들러
@@ -47,33 +55,27 @@ export async function handleLocalSearch(params) {
47
55
  * 뉴스 검색 핸들러
48
56
  */
49
57
  export async function handleNewsSearch(params) {
50
- return client.search({ type: "news", ...params });
58
+ return client.search("news", params);
51
59
  }
52
60
  /**
53
61
  * 블로그 검색 핸들러
54
62
  */
55
63
  export async function handleBlogSearch(params) {
56
- return client.search({ type: "blog", ...params });
64
+ return client.search("blog", params);
57
65
  }
58
66
  /**
59
67
  * 쇼핑 검색 핸들러
60
68
  */
61
69
  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 });
70
+ return client.search("shop", params);
69
71
  }
70
72
  /**
71
73
  * 카페글 검색 핸들러
72
74
  */
73
75
  export async function handleCafeArticleSearch(params) {
74
- return client.search({ type: "cafearticle", ...params });
76
+ return client.search("cafearticle", params);
75
77
  }
76
78
  export async function handleWebKrSearch(args) {
77
79
  const client = NaverSearchClient.getInstance();
78
- return await client.search({ type: "webkr", ...args });
80
+ return await client.search("webkr", args);
79
81
  }
package/dist/src/index.js CHANGED
@@ -1,20 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  import * as dotenv from "dotenv";
3
- dotenv.config();
3
+ import pkg from "../package.json" with { type: "json" };
4
+ console.error("[MCP] dotenv import 완료");
4
5
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
5
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
7
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
7
- import { NaverSearchClient } from "./naver-search.client.js";
8
- import { SearchArgsSchema } from "./schemas/search.schemas.js";
8
+ import { NaverSearchClient } from "./clients/naver-search.client.js";
9
9
  import { searchTools } from "./tools/search.tools.js";
10
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";
11
+ import { searchToolHandlers } from "./handlers/search.handlers.js";
12
+ import { datalabToolHandlers } from "./handlers/datalab.handlers.js";
13
+ dotenv.config();
14
+ console.error("[MCP] dotenv.config() 실행됨");
13
15
  // 환경 변수 유효성 검사
14
16
  const NAVER_CLIENT_ID = process.env.NAVER_CLIENT_ID;
15
17
  const NAVER_CLIENT_SECRET = process.env.NAVER_CLIENT_SECRET;
18
+ console.error("[MCP] 환경변수 읽음", { NAVER_CLIENT_ID, NAVER_CLIENT_SECRET });
16
19
  if (!NAVER_CLIENT_ID || !NAVER_CLIENT_SECRET) {
17
- console.error("Error: NAVER_CLIENT_ID and NAVER_CLIENT_SECRET environment variables are required");
20
+ console.error("[MCP] Error: NAVER_CLIENT_ID and NAVER_CLIENT_SECRET environment variables are required");
18
21
  process.exit(1);
19
22
  }
20
23
  // 네이버 검색 클라이언트 초기화
@@ -23,25 +26,32 @@ client.initialize({
23
26
  clientId: NAVER_CLIENT_ID,
24
27
  clientSecret: NAVER_CLIENT_SECRET,
25
28
  });
29
+ console.error("[MCP] NaverSearchClient 초기화 완료");
26
30
  // MCP 서버 인스턴스 생성
27
31
  const server = new Server({
28
32
  name: "naver-search",
29
- version: "1.0.14",
33
+ version: pkg.version,
30
34
  }, {
31
35
  capabilities: {
32
36
  tools: {},
33
37
  },
34
38
  });
39
+ console.error("[MCP] Server 인스턴스 생성 완료");
35
40
  // 도구 목록을 반환하는 핸들러 등록
36
41
  server.setRequestHandler(ListToolsRequestSchema, async () => {
42
+ console.error("[MCP] ListToolsRequestSchema 핸들러 호출됨");
37
43
  return {
38
44
  tools: [...searchTools, ...datalabTools],
39
45
  };
40
46
  });
47
+ const toolHandlers = {
48
+ ...searchToolHandlers,
49
+ ...datalabToolHandlers,
50
+ };
41
51
  // 에러 응답 헬퍼 함수
42
52
  function createErrorResponse(error) {
43
53
  const errorMessage = error instanceof Error ? error.message : String(error);
44
- console.error("API Error:", errorMessage);
54
+ console.error("[MCP] API Error:", errorMessage);
45
55
  return {
46
56
  content: [{ type: "text", text: `Error: ${errorMessage}` }],
47
57
  isError: true,
@@ -51,75 +61,15 @@ function createErrorResponse(error) {
51
61
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
52
62
  try {
53
63
  const { name, arguments: args } = request.params;
54
- console.error(`Executing tool: ${name} with args:`, args);
64
+ console.error(`[MCP] Executing tool: ${name} with args:`, args);
55
65
  if (!args) {
56
66
  throw new Error("Arguments are required");
57
67
  }
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`);
68
+ const handler = toolHandlers[name];
69
+ if (!handler)
70
+ throw new Error(`Unknown tool: ${name}`);
71
+ const result = await handler(args);
72
+ console.error(`[MCP] Tool ${name} executed successfully`);
123
73
  return {
124
74
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
125
75
  };
@@ -131,24 +81,26 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
131
81
  // 서버 시작 함수
132
82
  async function runServer() {
133
83
  try {
84
+ console.error("[MCP] runServer 진입");
134
85
  const transport = new StdioServerTransport();
135
86
  // 서버 에러 핸들링
136
87
  process.on("uncaughtException", (error) => {
137
- console.error("Uncaught Exception:", error);
88
+ console.error("[MCP] Uncaught Exception:", error);
138
89
  });
139
90
  process.on("unhandledRejection", (reason, promise) => {
140
- console.error("Unhandled Rejection at:", promise, "reason:", reason);
91
+ console.error("[MCP] Unhandled Rejection at:", promise, "reason:", reason);
141
92
  });
142
93
  await server.connect(transport);
143
- console.error("Naver Search MCP Server running on stdio");
94
+ console.error("[MCP] Naver Search MCP Server running on stdio");
144
95
  }
145
96
  catch (error) {
146
- console.error("Fatal error running server:", error);
97
+ console.error("[MCP] Fatal error running server:", error);
147
98
  process.exit(1);
148
99
  }
149
100
  }
150
101
  // 서버 시작
102
+ console.error("[MCP] runServer 호출 직전");
151
103
  runServer().catch((error) => {
152
- console.error("Fatal error running server:", error);
104
+ console.error("[MCP] Fatal error running server (catch):", error);
153
105
  process.exit(1);
154
106
  });
@@ -1,6 +1,19 @@
1
1
  import { z } from "zod";
2
- // 기본 검색 파라미터 스키마
3
- export const SearchArgsSchema = z.object({
2
+ // 네이버 검색 타입(카테고리)
3
+ export const NaverSearchTypeSchema = z.enum([
4
+ "news",
5
+ "encyc",
6
+ "blog",
7
+ "shop",
8
+ "webkr",
9
+ "image",
10
+ "doc",
11
+ "kin",
12
+ "book",
13
+ "cafearticle",
14
+ "local",
15
+ ]);
16
+ export const NaverSearchParamsSchema = z.object({
4
17
  query: z.string().describe("Search query"),
5
18
  display: z
6
19
  .number()
@@ -13,5 +26,37 @@ export const SearchArgsSchema = z.object({
13
26
  sort: z
14
27
  .enum(["sim", "date"])
15
28
  .optional()
16
- .describe("Sort method (sim: similarity, date: date)"),
29
+ .describe("Sort method (sim: similarity, date: chronological)"),
30
+ });
31
+ // 네이버 검색 공통 파라미터
32
+ export const SearchArgsSchema = z.object({
33
+ query: z.string().describe("검색어"),
34
+ display: z.number().optional().describe("한 번에 가져올 결과 수 (기본 10)"),
35
+ start: z.number().optional().describe("검색 시작 위치 (기본 1)"),
36
+ sort: z
37
+ .enum(["sim", "date"])
38
+ .optional()
39
+ .describe("정렬 방식 (sim: 유사도, date: 날짜순)"),
40
+ });
41
+ // 네이버 API 인증 정보
42
+ export const NaverSearchConfigSchema = z.object({
43
+ clientId: z.string().describe("네이버 개발자센터에서 발급받은 Client ID"),
44
+ clientSecret: z
45
+ .string()
46
+ .describe("네이버 개발자센터에서 발급받은 Client Secret"),
47
+ });
48
+ // 전문자료(논문 등) 검색 파라미터
49
+ export const NaverDocumentSearchParamsSchema = z.object({
50
+ query: z.string().describe("검색어"),
51
+ display: z.number().optional().describe("한 번에 가져올 결과 수 (최대 100)"),
52
+ start: z.number().optional().describe("검색 시작 위치 (최대 1000)"),
53
+ });
54
+ // 지역 검색 파라미터
55
+ export const NaverLocalSearchParamsSchema = SearchArgsSchema.extend({
56
+ sort: z
57
+ .enum(["random", "comment"])
58
+ .optional()
59
+ .describe("정렬 방식 (random: 정확도순, comment: 리뷰 많은순)"),
60
+ display: z.number().optional().describe("한 번에 가져올 결과 수 (최대 5)"),
61
+ start: z.number().optional().describe("검색 시작 위치 (최대 1)"),
17
62
  });
@@ -1,6 +1,5 @@
1
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";
2
+ import { SearchArgsSchema, NaverLocalSearchParamsSchema, } from "../schemas/search.schemas.js";
4
3
  /**
5
4
  * 검색 관련 도구 정의
6
5
  */
@@ -55,4 +54,9 @@ export const searchTools = [
55
54
  description: "Perform a search on Naver Local. (네이버 지역 검색)",
56
55
  inputSchema: zodToJsonSchema(NaverLocalSearchParamsSchema),
57
56
  },
57
+ {
58
+ name: "search_cafearticle",
59
+ description: "Perform a search on Naver Cafe Articles. (네이버 카페글 검색)",
60
+ inputSchema: zodToJsonSchema(SearchArgsSchema),
61
+ },
58
62
  ];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@isnow890/naver-search-mcp",
3
- "version": "1.0.14",
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
- }
1
+ {
2
+ "name": "@isnow890/naver-search-mcp",
3
+ "version": "1.0.18",
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": "1.10.2",
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
+ }
@@ -1,61 +0,0 @@
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
- });
@@ -1,61 +0,0 @@
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