From 66a403488f3a7bc32a02bc9933c396dc4c4e031d Mon Sep 17 00:00:00 2001 From: haoyuren <13851610112@163.com> Date: Sun, 15 Mar 2026 20:52:13 -0500 Subject: Add API key management UI and wire S2 key to MCP - Settings modal on project list page for OpenAI, Anthropic, OpenRouter, Gemini, Semantic Scholar keys - Keys stored in userData/api-keys.json, masked by default with show/hide toggle - S2 API key passed to MCP server via .lattex-mcp.json to avoid rate limits Co-Authored-By: Claude Opus 4.6 --- src/mcp/lattex.mjs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/mcp/lattex.mjs') diff --git a/src/mcp/lattex.mjs b/src/mcp/lattex.mjs index 65f6d87..64520f7 100644 --- a/src/mcp/lattex.mjs +++ b/src/mcp/lattex.mjs @@ -528,6 +528,13 @@ const TOOLS = [ // ── Semantic Scholar helpers ───────────────────────────────── +function getSemanticScholarApiKey() { + try { + const state = readState() + return state.semanticScholarApiKey || null + } catch { return null } +} + function semanticScholarSearch(query, limit) { return new Promise((resolve) => { const params = new URLSearchParams({ @@ -535,13 +542,14 @@ function semanticScholarSearch(query, limit) { limit: String(limit), fields: 'title,authors,year,externalIds,venue,publicationDate,abstract,citationCount' }) + const headers = { 'User-Agent': 'LatteX-MCP/1.0' } + const apiKey = getSemanticScholarApiKey() + if (apiKey) headers['x-api-key'] = apiKey const options = { hostname: 'api.semanticscholar.org', path: `/graph/v1/paper/search?${params}`, method: 'GET', - headers: { - 'User-Agent': 'LatteX-MCP/1.0' - } + headers } const req = https.request(options, (res) => { -- cgit v1.2.3