Sign In

@harukibox/mcp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harukibox/mcp - npm Package Compare versions

Comparing version
0.2.0
to
0.2.1
+86
-12
dist/index.js

@@ -23,3 +23,3 @@ #!/usr/bin/env node

import { findTool, TOOLS, toolDescriptor } from './tools.js';
import { buildCacheableResult, buildResult, getClientInfo, getDeclaredProtocolVersion, INTERNAL_ERROR, INVALID_REQUEST, LATEST_PROTOCOL_VERSION, METHOD_NOT_FOUND, negotiateLegacyVersion, PARSE_ERROR, resolveEra, SUPPORTED_PROTOCOL_VERSIONS, UNSUPPORTED_PROTOCOL_VERSION, unsupportedVersionData, } from './protocol.js';
import { buildCacheableResult, buildResult, getClientInfo, getDeclaredProtocolVersion, INTERNAL_ERROR, INVALID_REQUEST, LATEST_PROTOCOL_VERSION, INVALID_PARAMS, METHOD_NOT_FOUND, negotiateLegacyVersion, PARSE_ERROR, resolveEra, SUPPORTED_PROTOCOL_VERSIONS, UNSUPPORTED_PROTOCOL_VERSION, unsupportedVersionData, } from './protocol.js';
const SERVER_NAME = 'harukibox';

@@ -130,13 +130,43 @@ const SERVER_VERSION = '0.2.0';

/* -------------------------------------------------------------- handlers */
/**
* 把一個 JSON-RPC 請求原樣轉發給遠端 /api/agent/mcp,回傳它的 `result`。
*
* 為什麼要轉發而不是本地實作:工具清單原本硬編在這個套件裡,
* 伺服器每加一個工具就得重發 npm 套件,使用者不升級就看不到——
* 2026-08-03 實際發生過(伺服器已有 11 個工具,套件只宣告 8 個)。
* 轉發之後這個套件只負責 stdio ↔ HTTP 的橋接,能力永遠跟伺服器一致。
*
* 失敗時回 null,由呼叫端決定要用什麼形狀回覆。
*/
async function forward(method, params) {
const res = await client.request('POST', '/mcp', {
jsonrpc: '2.0',
id: 1,
method,
...(params === undefined ? {} : { params }),
});
const envelope = res;
if (envelope && typeof envelope === 'object' && envelope.result)
return envelope.result;
return null;
}
/** `tools/call` — API failures come back as `isError` results, not RPC errors. */
async function callTool(era, params) {
const name = typeof params.name === 'string' ? params.name : '';
const tool = findTool(name);
if (!tool) {
return toolResult(era, { success: false, message: `Unknown tool: ${name || '(empty)'}` });
if (!name) {
return toolResult(era, { success: false, message: 'Unknown tool: (empty)' });
}
const args = params.arguments && typeof params.arguments === 'object'
? params.arguments
: {};
try {
// 先問遠端:新工具不需要更新這個套件就能用
const remote = await forward('tools/call', params);
if (remote)
return remote;
// 遠端沒回 result(離線/舊版伺服器)→ 退回套件內建的實作
const tool = findTool(name);
if (!tool) {
return toolResult(era, { success: false, message: `Unknown tool: ${name}` });
}
const args = params.arguments && typeof params.arguments === 'object'
? params.arguments
: {};
return toolResult(era, await tool.call(client, args));

@@ -160,7 +190,23 @@ }

}
function listToolsResult(era) {
return buildCacheableResult(era, { tools: TOOLS.map(toolDescriptor) }, SERVER_IDENTITY, LIST_TTL_MS,
/**
* 工具清單以**伺服器為準**,本地那份只是離線後備。
*
* 硬編在套件裡的清單一定會過時:伺服器加工具、使用者沒升級 npm 套件,
* 就再也看不到新功能(2026-08-03 實際發生,套件少了 3 個工具)。
*/
async function listToolsResult(era) {
const remote = await forward('tools/list');
const tools = Array.isArray(remote?.tools) ? remote.tools : TOOLS.map(toolDescriptor);
return buildCacheableResult(era, { tools }, SERVER_IDENTITY, LIST_TTL_MS,
// The tool list is identical for every token — no user data in it.
'public');
}
/**
* prompts(伺服器提供的可重用工作流程)純轉發——本套件不自己定義。
* 遠端沒有就回空清單,而不是報錯:舊版伺服器沒有 prompts 是正常情況。
*/
async function listPromptsResult(era) {
const remote = await forward('prompts/list');
return buildCacheableResult(era, { prompts: Array.isArray(remote?.prompts) ? remote.prompts : [] }, SERVER_IDENTITY, LIST_TTL_MS, 'public');
}
function discoverResult() {

@@ -196,3 +242,3 @@ return buildCacheableResult('modern', {

case 'tools/list':
sendResult(id, listToolsResult(era));
sendResult(id, await listToolsResult(era));
return;

@@ -202,2 +248,14 @@ case 'tools/call':

return;
case 'prompts/list':
sendResult(id, await listPromptsResult(era));
return;
case 'prompts/get': {
const remote = await forward('prompts/get', params);
if (!remote) {
sendError(id, INVALID_PARAMS, 'Prompt not available');
return;
}
sendResult(id, remote);
return;
}
default:

@@ -221,3 +279,7 @@ // `initialize`, `ping` and `logging/setLevel` no longer exist in

serverInfo: SERVER_IDENTITY,
capabilities: { tools: { listChanged: false } },
capabilities: {
tools: { listChanged: false },
// 伺服器提供的可重用工作流程;本套件純轉發
prompts: { listChanged: false },
},
instructions: INSTRUCTIONS,

@@ -231,3 +293,3 @@ });

case 'tools/list':
sendResult(id, listToolsResult('legacy'));
sendResult(id, await listToolsResult('legacy'));
return;

@@ -237,2 +299,14 @@ case 'tools/call':

return;
case 'prompts/list':
sendResult(id, await listPromptsResult('legacy'));
return;
case 'prompts/get': {
const remote = await forward('prompts/get', params);
if (!remote) {
sendError(id, INVALID_PARAMS, 'Prompt not available');
return;
}
sendResult(id, remote);
return;
}
case 'server/discover':

@@ -239,0 +313,0 @@ // Unreachable — resolveEra always routes discover to the modern

{
"name": "@harukibox/mcp",
"version": "0.2.0",
"version": "0.2.1",
"mcpName": "com.harukibox/harukibox",
"private": false,

@@ -37,3 +38,12 @@ "description": "Model Context Protocol server for harukibox (MCP 2026-07-28, dual-era) — let your AI agent manage your inventory, orders, buyers and shipments through the official harukibox API.",

},
"keywords": ["harukibox", "mcp", "model-context-protocol", "mcp-2026-07-28", "claude", "agent", "japan-import", "代購"]
"keywords": [
"harukibox",
"mcp",
"model-context-protocol",
"mcp-2026-07-28",
"claude",
"agent",
"japan-import",
"代購"
]
}