@isnow890/naver-search-mcp 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -6,25 +6,9 @@
6
6
 
7
7
  MCP server for Naver Search API and DataLab API integration, enabling comprehensive search across various Naver services and data trend analysis.
8
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
9
  #### Information
26
10
 
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.**
11
+ 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
12
 
29
13
  #### Prerequisites
30
14
 
@@ -50,7 +34,6 @@ MCP server for Naver Search API and DataLab API integration, enabling comprehens
50
34
  - **search_webkr**: Search Naver web documents
51
35
  - **search_news**: Search Naver news
52
36
  - **search_blog**: Search Naver blogs
53
- - **search_cafearticle**: Search Naver cafe articles
54
37
  - **search_shop**: Search Naver shopping
55
38
  - **search_image**: Search Naver images
56
39
  - **search_kin**: Search Naver KnowledgeiN
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isnow890/naver-search-mcp",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Naver Search MCP Server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,42 +1,20 @@
1
- import { NaverSearchClient } from "../clients/naver-search.client.js";
2
- // 클라이언트 인스턴스 (싱글톤)
1
+ import { NaverSearchClient } from "../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
- };
20
4
  /**
21
5
  * 검색어 트렌드 핸들러
22
- * 네이버 데이터랩 검색어 트렌드 분석 API 호출
23
- * @param params DatalabSearch
24
6
  */
25
7
  export async function handleSearchTrend(params) {
26
8
  return client.searchTrend(params);
27
9
  }
28
10
  /**
29
11
  * 쇼핑 카테고리 트렌드 핸들러
30
- * 네이버 데이터랩 쇼핑 카테고리별 트렌드 분석 API 호출
31
- * @param params DatalabShopping
32
12
  */
33
13
  export async function handleShoppingCategoryTrend(params) {
34
14
  return client.datalabShoppingCategory(params);
35
15
  }
36
16
  /**
37
17
  * 쇼핑 기기별 트렌드 핸들러
38
- * 네이버 데이터랩 쇼핑 기기별 트렌드 분석 API 호출
39
- * @param params DatalabShoppingDevice
40
18
  */
41
19
  export async function handleShoppingByDeviceTrend(params) {
42
20
  return client.datalabShoppingByDevice({
@@ -49,8 +27,6 @@ export async function handleShoppingByDeviceTrend(params) {
49
27
  }
50
28
  /**
51
29
  * 쇼핑 성별 트렌드 핸들러
52
- * 네이버 데이터랩 쇼핑 성별 트렌드 분석 API 호출
53
- * @param params DatalabShoppingGender
54
30
  */
55
31
  export async function handleShoppingByGenderTrend(params) {
56
32
  return client.datalabShoppingByGender({
@@ -63,8 +39,6 @@ export async function handleShoppingByGenderTrend(params) {
63
39
  }
64
40
  /**
65
41
  * 쇼핑 연령별 트렌드 핸들러
66
- * 네이버 데이터랩 쇼핑 연령별 트렌드 분석 API 호출
67
- * @param params DatalabShoppingAge
68
42
  */
69
43
  export async function handleShoppingByAgeTrend(params) {
70
44
  return client.datalabShoppingByAge({
@@ -76,9 +50,8 @@ export async function handleShoppingByAgeTrend(params) {
76
50
  });
77
51
  }
78
52
  /**
79
- * 쇼핑 키워드 트렌드 핸들러 (복수 키워드 그룹 지원)
80
- * 네이버 데이터랩 쇼핑 키워드 그룹 트렌드 분석 API 호출
81
- * @param params DatalabShoppingKeywords
53
+ * 쇼핑 키워드 트렌드 핸들러
54
+ * 복수 키워드 그룹을 지원합니다.
82
55
  */
83
56
  export async function handleShoppingKeywordsTrend(params) {
84
57
  // 키워드 배열을 네이버 API에 맞는 형식으로 변환
@@ -87,13 +60,11 @@ export async function handleShoppingKeywordsTrend(params) {
87
60
  endDate: params.endDate,
88
61
  timeUnit: params.timeUnit,
89
62
  category: params.category,
90
- keyword: params.keyword,
63
+ keyword: params.keyword
91
64
  });
92
65
  }
93
66
  /**
94
67
  * 쇼핑 키워드 기기별 트렌드 핸들러
95
- * 네이버 데이터랩 쇼핑 키워드 기기별 트렌드 분석 API 호출
96
- * @param params DatalabShoppingKeywordDevice
97
68
  */
98
69
  export async function handleShoppingKeywordByDeviceTrend(params) {
99
70
  return client.datalabShoppingKeywordByDevice({
@@ -107,8 +78,6 @@ export async function handleShoppingKeywordByDeviceTrend(params) {
107
78
  }
108
79
  /**
109
80
  * 쇼핑 키워드 성별 트렌드 핸들러
110
- * 네이버 데이터랩 쇼핑 키워드 성별 트렌드 분석 API 호출
111
- * @param params DatalabShoppingKeywordGender
112
81
  */
113
82
  export async function handleShoppingKeywordByGenderTrend(params) {
114
83
  return client.datalabShoppingKeywordByGender({
@@ -122,8 +91,6 @@ export async function handleShoppingKeywordByGenderTrend(params) {
122
91
  }
123
92
  /**
124
93
  * 쇼핑 키워드 연령별 트렌드 핸들러
125
- * 네이버 데이터랩 쇼핑 키워드 연령별 트렌드 분석 API 호출
126
- * @param params DatalabShoppingKeywordAge
127
94
  */
128
95
  export async function handleShoppingKeywordByAgeTrend(params) {
129
96
  return client.datalabShoppingKeywordByAge({
@@ -1,20 +1,6 @@
1
- import { NaverSearchClient } from "../clients/naver-search.client.js";
2
- import { SearchArgsSchema } from "../schemas/search.schemas.js";
1
+ import { NaverSearchClient } from "../naver-search.client.js";
3
2
  // 클라이언트 인스턴스
4
3
  const client = NaverSearchClient.getInstance();
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
- };
18
4
  /**
19
5
  * 전문자료 검색 핸들러
20
6
  */
@@ -25,25 +11,25 @@ export async function handleAcademicSearch(params) {
25
11
  * 도서 검색 핸들러
26
12
  */
27
13
  export async function handleBookSearch(params) {
28
- return client.search("book", params);
14
+ return client.search({ type: "book", ...params });
29
15
  }
30
16
  /**
31
17
  * 지식백과 검색 핸들러
32
18
  */
33
19
  export async function handleEncycSearch(params) {
34
- return client.search("encyc", params);
20
+ return client.search({ type: "encyc", ...params });
35
21
  }
36
22
  /**
37
23
  * 이미지 검색 핸들러
38
24
  */
39
25
  export async function handleImageSearch(params) {
40
- return client.search("image", params);
26
+ return client.search({ type: "image", ...params });
41
27
  }
42
28
  /**
43
29
  * 지식iN 검색 핸들러
44
30
  */
45
31
  export async function handleKinSearch(params) {
46
- return client.search("kin", params);
32
+ return client.search({ type: "kin", ...params });
47
33
  }
48
34
  /**
49
35
  * 지역 검색 핸들러
@@ -55,27 +41,27 @@ export async function handleLocalSearch(params) {
55
41
  * 뉴스 검색 핸들러
56
42
  */
57
43
  export async function handleNewsSearch(params) {
58
- return client.search("news", params);
44
+ return client.search({ type: "news", ...params });
59
45
  }
60
46
  /**
61
47
  * 블로그 검색 핸들러
62
48
  */
63
49
  export async function handleBlogSearch(params) {
64
- return client.search("blog", params);
50
+ return client.search({ type: "blog", ...params });
65
51
  }
66
52
  /**
67
53
  * 쇼핑 검색 핸들러
68
54
  */
69
55
  export async function handleShopSearch(params) {
70
- return client.search("shop", params);
56
+ return client.search({ type: "shop", ...params });
71
57
  }
72
58
  /**
73
59
  * 카페글 검색 핸들러
74
60
  */
75
61
  export async function handleCafeArticleSearch(params) {
76
- return client.search("cafearticle", params);
62
+ return client.search({ type: "cafearticle", ...params });
77
63
  }
78
64
  export async function handleWebKrSearch(args) {
79
65
  const client = NaverSearchClient.getInstance();
80
- return await client.search("webkr", args);
66
+ return await client.search({ type: "webkr", ...args });
81
67
  }
package/dist/src/index.js CHANGED
@@ -1,14 +1,16 @@
1
+ #!/usr/bin/env node
1
2
  import * as dotenv from "dotenv";
2
3
  import pkg from "../package.json" with { type: "json" };
4
+ dotenv.config();
3
5
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
7
  import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
6
- import { NaverSearchClient } from "./clients/naver-search.client.js";
8
+ import { NaverSearchClient } from "./naver-search.client.js";
9
+ import { SearchArgsSchema } from "./schemas/search.schemas.js";
7
10
  import { searchTools } from "./tools/search.tools.js";
8
11
  import { datalabTools } from "./tools/datalab.tools.js";
9
- import { searchToolHandlers } from "./handlers/search.handlers.js";
10
- import { datalabToolHandlers } from "./handlers/datalab.handlers.js";
11
- dotenv.config();
12
+ import { handleAcademicSearch, handleBlogSearch, handleBookSearch, handleCafeArticleSearch, handleEncycSearch, handleImageSearch, handleKinSearch, handleLocalSearch, handleNewsSearch, handleShopSearch, handleWebKrSearch, } from "./handlers/search.handlers.js";
13
+ import { handleSearchTrend, handleShoppingByAgeTrend, handleShoppingByDeviceTrend, handleShoppingByGenderTrend, handleShoppingCategoryTrend, handleShoppingKeywordByAgeTrend, handleShoppingKeywordByDeviceTrend, handleShoppingKeywordByGenderTrend, handleShoppingKeywordsTrend, } from "./handlers/datalab.handlers.js";
12
14
  // 환경 변수 유효성 검사
13
15
  const NAVER_CLIENT_ID = process.env.NAVER_CLIENT_ID;
14
16
  const NAVER_CLIENT_SECRET = process.env.NAVER_CLIENT_SECRET;
@@ -37,10 +39,6 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
37
39
  tools: [...searchTools, ...datalabTools],
38
40
  };
39
41
  });
40
- const toolHandlers = {
41
- ...searchToolHandlers,
42
- ...datalabToolHandlers,
43
- };
44
42
  // 에러 응답 헬퍼 함수
45
43
  function createErrorResponse(error) {
46
44
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -58,10 +56,73 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
58
56
  if (!args) {
59
57
  throw new Error("Arguments are required");
60
58
  }
61
- const handler = toolHandlers[name];
62
- if (!handler)
63
- throw new Error(`Unknown tool: ${name}`);
64
- const result = await handler(args);
59
+ let result;
60
+ switch (name) {
61
+ // 검색 API
62
+ case "search_webkr":
63
+ result = await handleWebKrSearch(SearchArgsSchema.parse(args));
64
+ break;
65
+ case "search_news":
66
+ result = await handleNewsSearch(SearchArgsSchema.parse(args));
67
+ break;
68
+ case "search_blog":
69
+ result = await handleBlogSearch(SearchArgsSchema.parse(args));
70
+ break;
71
+ case "search_shop":
72
+ result = await handleShopSearch(SearchArgsSchema.parse(args));
73
+ break;
74
+ case "search_image":
75
+ result = await handleImageSearch(SearchArgsSchema.parse(args));
76
+ break;
77
+ case "search_kin":
78
+ result = await handleKinSearch(SearchArgsSchema.parse(args));
79
+ break;
80
+ case "search_book":
81
+ result = await handleBookSearch(SearchArgsSchema.parse(args));
82
+ break;
83
+ case "search_encyc":
84
+ result = await handleEncycSearch(SearchArgsSchema.parse(args));
85
+ break;
86
+ case "search_academic":
87
+ result = await handleAcademicSearch(SearchArgsSchema.parse(args));
88
+ break;
89
+ case "search_local":
90
+ result = await handleLocalSearch(args);
91
+ break;
92
+ case "search_cafearticle":
93
+ result = await handleCafeArticleSearch(args);
94
+ break;
95
+ // 데이터랩 API
96
+ case "datalab_search":
97
+ result = await handleSearchTrend(args);
98
+ break;
99
+ case "datalab_shopping_category":
100
+ result = await handleShoppingCategoryTrend(args);
101
+ break;
102
+ case "datalab_shopping_by_device":
103
+ result = await handleShoppingByDeviceTrend(args);
104
+ break;
105
+ case "datalab_shopping_by_gender":
106
+ result = await handleShoppingByGenderTrend(args);
107
+ break;
108
+ case "datalab_shopping_by_age":
109
+ result = await handleShoppingByAgeTrend(args);
110
+ break;
111
+ case "datalab_shopping_keywords":
112
+ result = await handleShoppingKeywordsTrend(args);
113
+ break;
114
+ case "datalab_shopping_keyword_by_device":
115
+ result = await handleShoppingKeywordByDeviceTrend(args);
116
+ break;
117
+ case "datalab_shopping_keyword_by_gender":
118
+ result = await handleShoppingKeywordByGenderTrend(args);
119
+ break;
120
+ case "datalab_shopping_keyword_by_age":
121
+ result = await handleShoppingKeywordByAgeTrend(args);
122
+ break;
123
+ default:
124
+ throw new Error(`Unknown tool: ${name}`);
125
+ }
65
126
  console.error(`Tool ${name} executed successfully`);
66
127
  return {
67
128
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
@@ -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;
@@ -1,47 +1,17 @@
1
1
  import { z } from "zod";
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
- // 네이버 검색 공통 파라미터
2
+ // 기본 검색 파라미터 스키마
17
3
  export const SearchArgsSchema = z.object({
18
- query: z.string().describe("검색어"),
19
- display: z.number().optional().describe("한 번에 가져올 결과 수 (기본 10)"),
20
- start: z.number().optional().describe("검색 시작 위치 (기본 1)"),
21
- sort: z
22
- .enum(["sim", "date"])
4
+ query: z.string().describe("Search query"),
5
+ display: z
6
+ .number()
23
7
  .optional()
24
- .describe("정렬 방식 (sim: 유사도, date: 날짜순)"),
25
- });
26
- // 네이버 API 인증 정보
27
- export const NaverSearchConfigSchema = z.object({
28
- clientId: z.string().describe("네이버 개발자센터에서 발급받은 Client ID"),
29
- clientSecret: z
30
- .string()
31
- .describe("네이버 개발자센터에서 발급받은 Client Secret"),
32
- });
33
- // 전문자료(논문 등) 검색 파라미터
34
- export const NaverDocumentSearchParamsSchema = z.object({
35
- query: z.string().describe("검색어"),
36
- display: z.number().optional().describe("한 번에 가져올 결과 수 (최대 100)"),
37
- start: z.number().optional().describe("검색 시작 위치 (최대 1000)"),
38
- });
39
- // 지역 검색 파라미터
40
- export const NaverLocalSearchParamsSchema = SearchArgsSchema.extend({
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)"),
41
13
  sort: z
42
- .enum(["random", "comment"])
14
+ .enum(["sim", "date"])
43
15
  .optional()
44
- .describe("정렬 방식 (random: 정확도순, comment: 리뷰 많은순)"),
45
- display: z.number().optional().describe("한 번에 가져올 결과 수 (최대 5)"),
46
- start: z.number().optional().describe("검색 시작 위치 (최대 1)"),
16
+ .describe("Sort method (sim: similarity, date: date)"),
47
17
  });
@@ -1,5 +1,6 @@
1
1
  import { zodToJsonSchema } from "zod-to-json-schema";
2
- import { SearchArgsSchema, NaverLocalSearchParamsSchema, } from "../schemas/search.schemas.js";
2
+ import { SearchArgsSchema } from "../schemas/search.schemas.js";
3
+ import { NaverLocalSearchParamsSchema } from "../types/naver-search.types.js";
3
4
  /**
4
5
  * 검색 관련 도구 정의
5
6
  */
@@ -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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isnow890/naver-search-mcp",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Naver Search MCP Server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,30 +0,0 @@
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
- }
@@ -1,100 +0,0 @@
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 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};