@him0/freee-mcp 0.2.3 → 0.2.4
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/bin/cli.js +10 -10
- package/dist/auth/oauth.d.ts +1 -1
- package/dist/auth/server.d.ts +2 -0
- package/dist/index.cjs +10 -10
- package/dist/index.esm.js +10 -10
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import{McpServer as ge}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as he}from"@modelcontextprotocol/sdk/server/stdio.js";var N=parseInt(process.env.FREEE_CALLBACK_PORT||"8080",10),p={freee:{clientId:process.env.FREEE_CLIENT_ID||"",clientSecret:process.env.FREEE_CLIENT_SECRET||"",companyId:process.env.FREEE_COMPANY_ID||"0",apiUrl:"https://api.freee.co.jp"},oauth:{callbackPort:N,redirectUri:`http://127.0.0.1:${N}/callback`,authorizationEndpoint:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenEndpoint:"https://accounts.secure.freee.co.jp/public_api/token",scope:"read write"},server:{name:"freee",version:"1.0.0"},auth:{timeoutMs:5*60*1e3}};import oe from"http";import{URL as pe}from"url";import se from"net";import O from"crypto";import y from"fs/promises";import h from"path";import k from"os";function R(){let t=h.join(k.homedir(),".config","freee-mcp");return h.join(t,"tokens.json")}async function v(t){let e=R(),n=h.dirname(e);try{console.error(`\u{1F4C1} Creating directory: ${n}`),await y.mkdir(n,{recursive:!0}),console.error(`\u{1F4BE} Writing tokens to: ${e}`),await y.writeFile(e,JSON.stringify(t,null,2),{mode:384}),console.error("\u2705 Tokens saved successfully")}catch(i){throw console.error("\u274C Failed to save tokens:",i),i}}async function I(){let t=R();try{let e=await y.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=await ie();return n||null}throw console.error("Failed to load tokens:",e),e}}function ne(t){return Date.now()<t.expires_at}async function ie(){let t=h.join(k.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));if(n.length>0){let i=h.join(t,n[0]),a=await y.readFile(i,"utf8"),r=JSON.parse(a);return await v(r),await Promise.all(n.map(o=>y.unlink(h.join(t,o)).catch(()=>{}))),console.error("\u2705 Migrated legacy company-specific tokens to user-based tokens"),r}}catch{}return null}async function re(t){let e=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:p.freee.clientId,client_secret:p.freee.clientSecret})});if(!e.ok){let a=await e.json().catch(()=>({}));throw new Error(`Token refresh failed: ${e.status} ${JSON.stringify(a)}`)}let n=await e.json(),i={access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+n.expires_in*1e3,token_type:n.token_type||"Bearer",scope:n.scope||p.oauth.scope};return await v(i),i}async function F(){let t=R();try{await y.unlink(t),console.error("Tokens cleared successfully")}catch(e){if(e.code==="ENOENT"){console.error("No tokens to clear (file does not exist)");return}throw console.error("Failed to clear tokens:",e),e}await ae()}async function ae(){let t=h.join(k.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));await Promise.all(n.map(i=>y.unlink(h.join(t,i)).catch(()=>{}))),n.length>0&&console.error("\u2705 Cleared legacy company-specific token files")}catch{}}async function U(){let t=await I();if(!t)return null;if(ne(t))return t.access_token;try{return(await re(t.refresh_token)).access_token}catch(e){return console.error("Failed to refresh token:",e),null}}function J(){let t=O.randomBytes(32).toString("base64url"),e=O.createHash("sha256").update(t).digest("base64url");return{codeVerifier:t,codeChallenge:e}}function B(t,e,n){let i=new URLSearchParams({response_type:"code",client_id:p.freee.clientId,redirect_uri:n,scope:p.oauth.scope,state:e,code_challenge:t,code_challenge_method:"S256"});return`${p.oauth.authorizationEndpoint}?${i.toString()}`}async function W(t,e){let n=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:p.freee.clientId,client_secret:p.freee.clientSecret,code:t,redirect_uri:p.oauth.redirectUri,code_verifier:e})});if(!n.ok){let r=await n.json().catch(()=>({}));throw new Error(`Token exchange failed: ${n.status} ${JSON.stringify(r)}`)}let i=await n.json(),a={access_token:i.access_token,refresh_token:i.refresh_token,expires_at:Date.now()+i.expires_in*1e3,token_type:i.token_type||"Bearer",scope:i.scope||p.oauth.scope};return await v(a),a}var f=null,_=new Map;async function me(t){return new Promise(e=>{let n=se.createServer();n.listen(t,"127.0.0.1",()=>{n.close(()=>{e(!0)})}),n.on("error",()=>{e(!1)})})}async function M(){if(f)return;let t=p.oauth.callbackPort;if(!await me(t))throw new Error(`Port ${t} is already in use. Please close other applications using this port.`);return new Promise((n,i)=>{f=oe.createServer((a,r)=>{console.error(`\u{1F4E5} Callback request: ${a.method} ${a.url}`);let o=new pe(a.url,`http://127.0.0.1:${t}`);o.pathname==="/callback"?ce(o,r):o.pathname==="/"?(r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>freee MCP OAuth Server</h1><p>\u30B3\u30FC\u30EB\u30D0\u30C3\u30AF\u30B5\u30FC\u30D0\u30FC\u304C\u7A3C\u50CD\u4E2D\u3067\u3059\u3002</p>")):(r.writeHead(404,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>404 Not Found</h1><p>\u3053\u306E\u30D1\u30B9\u306F\u5B58\u5728\u3057\u307E\u305B\u3093\u3002</p>"))}),f.on("error",a=>{console.error("Callback server error:",a),i(a)}),f.listen(t,"127.0.0.1",()=>{console.error(`\u{1F517} OAuth callback server listening on http://127.0.0.1:${t}`),n()})})}function G(t,e){console.error(`\u{1F510} Registering authentication request with state: ${t.substring(0,10)}...`),console.error(`\u{1F510} Code verifier: ${e.substring(0,10)}...`);let n=setTimeout(()=>{_.delete(t),console.error(`\u23F0 Authentication timeout for state: ${t.substring(0,10)}...`)},p.auth.timeoutMs);_.set(t,{codeVerifier:e,resolve:i=>{console.error("\u{1F389} Authentication completed successfully!")},reject:i=>{console.error("\u274C Authentication failed:",i)},timeout:n}),console.error(`\u{1F4DD} Registration complete. Total pending: ${_.size}`)}function P(){if(f){for(let[t,e]of _)clearTimeout(e.timeout),e.reject(new Error("Server shutdown"));_.clear(),f.close(()=>{console.error("\u{1F534} OAuth callback server stopped")}),f=null}}function ce(t,e){let n=t.searchParams.get("code"),i=t.searchParams.get("state"),a=t.searchParams.get("error"),r=t.searchParams.get("error_description");if(console.error(`\u{1F50D} Callback received - URL: ${t.toString()}`),console.error("\u{1F50D} Callback parameters:",{code:n?`${n.substring(0,10)}...`:null,state:i?`${i.substring(0,10)}...`:null,error:a,errorDescription:r}),console.error(`\u{1F50D} Pending authentications count: ${_.size}`),a){let s=r||a;if(console.error(`\u274C OAuth error: ${a} - ${r}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end(`<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${s}</p>`),i&&_.has(i)){let c=_.get(i);clearTimeout(c.timeout),c.reject(new Error(`OAuth error: ${a} - ${r}`)),_.delete(i)}return}if(!n||!i){console.error("\u274C Missing code or state"),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u30B3\u30FC\u30C9\u307E\u305F\u306F\u72B6\u614B\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002</p>");return}let o=_.get(i);if(!o){console.error(`\u274C Unknown state: ${i}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u4E0D\u660E\u306A\u8A8D\u8A3C\u72B6\u614B\u3067\u3059\u3002\u8A8D\u8A3C\u3092\u518D\u958B\u3057\u3066\u304F\u3060\u3055\u3044\u3002</p>");return}console.error("\u2705 Valid callback received, exchanging code for tokens..."),e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u5B8C\u4E86</h1><p>\u8A8D\u8A3C\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002\u3053\u306E\u30DA\u30FC\u30B8\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002</p>"),clearTimeout(o.timeout),_.delete(i),W(n,o.codeVerifier).then(s=>{console.error("\u{1F389} Token exchange successful!"),o.resolve(s)}).catch(s=>{console.error("\u274C Token exchange failed:",s),o.reject(s)})}import ue from"crypto";import{z as C}from"zod";import T from"fs/promises";import A from"path";import le from"os";function S(){let t=A.join(le.homedir(),".config","freee-mcp");return A.join(t,"config.json")}async function de(){let t=A.dirname(S());await T.mkdir(t,{recursive:!0})}async function $(){let t=S();try{let e=await T.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=p.freee.companyId||"0",i={defaultCompanyId:n,currentCompanyId:n,companies:{[n]:{id:n,name:"Default Company",description:"Company from environment variable",addedAt:Date.now(),lastUsed:Date.now()}}};return await V(i),i}throw e}}async function V(t){await de();let e=S();await T.writeFile(e,JSON.stringify(t,null,2),{mode:384})}async function g(){return(await $()).currentCompanyId}async function Z(t,e,n){let i=await $();i.companies[t]?(e||n)&&(e&&(i.companies[t].name=e),n&&(i.companies[t].description=n)):i.companies[t]={id:t,name:e||`Company ${t}`,description:n||void 0,addedAt:Date.now()},i.companies[t].lastUsed=Date.now(),i.currentCompanyId=t,await V(i)}async function E(){let t=await $();return Object.values(t.companies).sort((e,n)=>(n.lastUsed||0)-(e.lastUsed||0))}async function q(t){return(await $()).companies[t]||null}async function w(t,e,n,i){let a=p.freee.apiUrl,r=await g(),o=await U();if(!o)throw new Error(`\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
3
|
+
import{McpServer as xe}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as be}from"@modelcontextprotocol/sdk/server/stdio.js";var U=parseInt(process.env.FREEE_CALLBACK_PORT||"8080",10),p={freee:{clientId:process.env.FREEE_CLIENT_ID||"",clientSecret:process.env.FREEE_CLIENT_SECRET||"",companyId:process.env.FREEE_COMPANY_ID||"0",apiUrl:"https://api.freee.co.jp"},oauth:{callbackPort:U,redirectUri:`http://127.0.0.1:${U}/callback`,authorizationEndpoint:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenEndpoint:"https://accounts.secure.freee.co.jp/public_api/token",scope:"read write"},server:{name:"freee",version:"1.0.0"},auth:{timeoutMs:5*60*1e3}};import se from"http";import{URL as me}from"url";import ce from"net";import B from"crypto";import y from"fs/promises";import h from"path";import R from"os";function P(){let t=h.join(R.homedir(),".config","freee-mcp");return h.join(t,"tokens.json")}async function v(t){let e=P(),n=h.dirname(e);try{console.error(`\u{1F4C1} Creating directory: ${n}`),await y.mkdir(n,{recursive:!0}),console.error(`\u{1F4BE} Writing tokens to: ${e}`),await y.writeFile(e,JSON.stringify(t,null,2),{mode:384}),console.error("\u2705 Tokens saved successfully")}catch(i){throw console.error("\u274C Failed to save tokens:",i),i}}async function I(){let t=P();try{let e=await y.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=await ae();return n||null}throw console.error("Failed to load tokens:",e),e}}function re(t){return Date.now()<t.expires_at}async function ae(){let t=h.join(R.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));if(n.length>0){let i=h.join(t,n[0]),a=await y.readFile(i,"utf8"),r=JSON.parse(a);return await v(r),await Promise.all(n.map(o=>y.unlink(h.join(t,o)).catch(()=>{}))),console.error("\u2705 Migrated legacy company-specific tokens to user-based tokens"),r}}catch{}return null}async function oe(t){let e=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:p.freee.clientId,client_secret:p.freee.clientSecret})});if(!e.ok){let a=await e.json().catch(()=>({}));throw new Error(`Token refresh failed: ${e.status} ${JSON.stringify(a)}`)}let n=await e.json(),i={access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+n.expires_in*1e3,token_type:n.token_type||"Bearer",scope:n.scope||p.oauth.scope};return await v(i),i}async function O(){let t=P();try{await y.unlink(t),console.error("Tokens cleared successfully")}catch(e){if(e.code==="ENOENT"){console.error("No tokens to clear (file does not exist)");return}throw console.error("Failed to clear tokens:",e),e}await pe()}async function pe(){let t=h.join(R.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));await Promise.all(n.map(i=>y.unlink(h.join(t,i)).catch(()=>{}))),n.length>0&&console.error("\u2705 Cleared legacy company-specific token files")}catch{}}async function J(){let t=await I();if(!t)return null;if(re(t))return t.access_token;try{return(await oe(t.refresh_token)).access_token}catch(e){return console.error("Failed to refresh token:",e),null}}function W(){let t=B.randomBytes(32).toString("base64url"),e=B.createHash("sha256").update(t).digest("base64url");return{codeVerifier:t,codeChallenge:e}}function M(t,e,n){let i=new URLSearchParams({response_type:"code",client_id:p.freee.clientId,redirect_uri:n,scope:p.oauth.scope,state:e,code_challenge:t,code_challenge_method:"S256"});return`${p.oauth.authorizationEndpoint}?${i.toString()}`}async function G(t,e,n){let i=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:p.freee.clientId,client_secret:p.freee.clientSecret,code:t,redirect_uri:n,code_verifier:e})});if(!i.ok){let o=await i.json().catch(()=>({}));throw new Error(`Token exchange failed: ${i.status} ${JSON.stringify(o)}`)}let a=await i.json(),r={access_token:a.access_token,refresh_token:a.refresh_token,expires_at:Date.now()+a.expires_in*1e3,token_type:a.token_type||"Bearer",scope:a.scope||p.oauth.scope};return await v(r),r}var f=null,$=null,_=new Map;async function le(t){return new Promise(e=>{let n=ce.createServer();n.listen(t,"127.0.0.1",()=>{n.close(()=>{e(!0)})}),n.on("error",()=>{e(!1)})})}async function de(t,e=50){for(let n=t;n<t+e;n++)if(await le(n))return n;throw new Error(`No available port found after checking ${e} ports starting from ${t}`)}function A(){if($===null)throw new Error("Callback server not started. Call startCallbackServer() first.");return`http://127.0.0.1:${$}/callback`}async function V(){if(f)return;let t=p.oauth.callbackPort,e=await de(t);return $=e,e!==t&&console.error(`\u26A0\uFE0F Port ${t} is in use. Using fallback port ${e} for OAuth callback server.`),new Promise((n,i)=>{f=se.createServer((a,r)=>{console.error(`\u{1F4E5} Callback request: ${a.method} ${a.url}`);let o=new me(a.url,`http://127.0.0.1:${e}`);o.pathname==="/callback"?ue(o,r):o.pathname==="/"?(r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>freee MCP OAuth Server</h1><p>\u30B3\u30FC\u30EB\u30D0\u30C3\u30AF\u30B5\u30FC\u30D0\u30FC\u304C\u7A3C\u50CD\u4E2D\u3067\u3059\u3002</p>")):(r.writeHead(404,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>404 Not Found</h1><p>\u3053\u306E\u30D1\u30B9\u306F\u5B58\u5728\u3057\u307E\u305B\u3093\u3002</p>"))}),f.on("error",a=>{console.error("Callback server error:",a),i(a)}),f.listen(e,"127.0.0.1",()=>{console.error(`\u{1F517} OAuth callback server listening on http://127.0.0.1:${e}`),n()})})}function Z(t,e){console.error(`\u{1F510} Registering authentication request with state: ${t.substring(0,10)}...`),console.error(`\u{1F510} Code verifier: ${e.substring(0,10)}...`);let n=setTimeout(()=>{_.delete(t),console.error(`\u23F0 Authentication timeout for state: ${t.substring(0,10)}...`)},p.auth.timeoutMs);_.set(t,{codeVerifier:e,resolve:i=>{console.error("\u{1F389} Authentication completed successfully!")},reject:i=>{console.error("\u274C Authentication failed:",i)},timeout:n}),console.error(`\u{1F4DD} Registration complete. Total pending: ${_.size}`)}function T(){if(f){for(let[t,e]of _)clearTimeout(e.timeout),e.reject(new Error("Server shutdown"));_.clear(),f.close(()=>{console.error("\u{1F534} OAuth callback server stopped")}),f=null,$=null}}function ue(t,e){let n=t.searchParams.get("code"),i=t.searchParams.get("state"),a=t.searchParams.get("error"),r=t.searchParams.get("error_description");if(console.error(`\u{1F50D} Callback received - URL: ${t.toString()}`),console.error("\u{1F50D} Callback parameters:",{code:n?`${n.substring(0,10)}...`:null,state:i?`${i.substring(0,10)}...`:null,error:a,errorDescription:r}),console.error(`\u{1F50D} Pending authentications count: ${_.size}`),a){let s=r||a;if(console.error(`\u274C OAuth error: ${a} - ${r}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end(`<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${s}</p>`),i&&_.has(i)){let c=_.get(i);clearTimeout(c.timeout),c.reject(new Error(`OAuth error: ${a} - ${r}`)),_.delete(i)}return}if(!n||!i){console.error("\u274C Missing code or state"),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u30B3\u30FC\u30C9\u307E\u305F\u306F\u72B6\u614B\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002</p>");return}let o=_.get(i);if(!o){console.error(`\u274C Unknown state: ${i}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u4E0D\u660E\u306A\u8A8D\u8A3C\u72B6\u614B\u3067\u3059\u3002\u8A8D\u8A3C\u3092\u518D\u958B\u3057\u3066\u304F\u3060\u3055\u3044\u3002</p>");return}console.error("\u2705 Valid callback received, exchanging code for tokens..."),e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u5B8C\u4E86</h1><p>\u8A8D\u8A3C\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002\u3053\u306E\u30DA\u30FC\u30B8\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002</p>"),clearTimeout(o.timeout),_.delete(i),G(n,o.codeVerifier,A()).then(s=>{console.error("\u{1F389} Token exchange successful!"),o.resolve(s)}).catch(s=>{console.error("\u274C Token exchange failed:",s),o.reject(s)})}import ge from"crypto";import{z}from"zod";import C from"fs/promises";import S from"path";import _e from"os";function L(){let t=S.join(_e.homedir(),".config","freee-mcp");return S.join(t,"config.json")}async function ye(){let t=S.dirname(L());await C.mkdir(t,{recursive:!0})}async function E(){let t=L();try{let e=await C.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=p.freee.companyId||"0",i={defaultCompanyId:n,currentCompanyId:n,companies:{[n]:{id:n,name:"Default Company",description:"Company from environment variable",addedAt:Date.now(),lastUsed:Date.now()}}};return await Y(i),i}throw e}}async function Y(t){await ye();let e=L();await C.writeFile(e,JSON.stringify(t,null,2),{mode:384})}async function g(){return(await E()).currentCompanyId}async function H(t,e,n){let i=await E();i.companies[t]?(e||n)&&(e&&(i.companies[t].name=e),n&&(i.companies[t].description=n)):i.companies[t]={id:t,name:e||`Company ${t}`,description:n||void 0,addedAt:Date.now()},i.companies[t].lastUsed=Date.now(),i.currentCompanyId=t,await Y(i)}async function k(){let t=await E();return Object.values(t.companies).sort((e,n)=>(n.lastUsed||0)-(e.lastUsed||0))}async function q(t){return(await E()).companies[t]||null}async function w(t,e,n,i){let a=p.freee.apiUrl,r=await g(),o=await J();if(!o)throw new Error(`\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
4
4
|
\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${r}
|
|
5
5
|
\u307E\u305F\u306F\u3001FREEE_CLIENT_ID\u74B0\u5883\u5909\u6570\u304C\u6B63\u3057\u304F\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u304B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);let s=new URL(e,a);n&&Object.entries(n).forEach(([m,d])=>{d!==void 0&&s.searchParams.append(m,String(d))}),s.searchParams.append("company_id",String(r));let c=await fetch(s.toString(),{method:t,headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:i?JSON.stringify(typeof i=="string"?JSON.parse(i):i):void 0});if(c.status===401||c.status===403){let m=await c.json().catch(()=>({}));throw new Error(`\u8A8D\u8A3C\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u518D\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
6
6
|
\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${r}
|
|
@@ -20,7 +20,7 @@ ${x.join(`
|
|
|
20
20
|
\u65E2\u5B58\u306E\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u3066\u6B63\u3057\u3044\u69CB\u9020\u3092\u78BA\u8A8D\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059\u3002`,d+=`
|
|
21
21
|
\u4F8B: get_items, get_partners, get_account_items \u306A\u3069\u3067\u65E2\u5B58\u30C7\u30FC\u30BF\u306E\u69CB\u9020\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`))}throw m?.errors||(d+=`
|
|
22
22
|
|
|
23
|
-
\u8A73\u7D30: ${JSON.stringify(m)}`),new Error(d)}return c.json()}function
|
|
23
|
+
\u8A73\u7D30: ${JSON.stringify(m)}`),new Error(d)}return c.json()}function K(t){t.tool("freee_current_user","freee API\u306E\u73FE\u5728\u306E\u30E6\u30FC\u30B6\u30FC\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u8A8D\u8A3C\u72B6\u614B\u3001\u4E8B\u696D\u6240ID\u3001\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30\u304C\u542B\u307E\u308C\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30C6\u30B9\u30C8\u7528\u30FBAPI\u52D5\u4F5C\u78BA\u8A8D\u306B\u6700\u9069\u3011",{},async()=>{try{let e=await g(),n=await q(e);if(!e)return{content:[{type:"text",text:"\u4F1A\u793EID\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002freee_set_company \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u4F1A\u793E\u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"}]};let i=await w("GET","/api/1/users/me");return{content:[{type:"text",text:`\u73FE\u5728\u306E\u30E6\u30FC\u30B6\u30FC\u60C5\u5831:
|
|
24
24
|
\u73FE\u5728\u306E\u4F1A\u793EID: ${e}
|
|
25
25
|
\u4F1A\u793E\u540D: ${n?.name||"Unknown"}
|
|
26
26
|
\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30:
|
|
@@ -35,7 +35,7 @@ ${JSON.stringify(i,null,2)}`}]}}catch(e){return{content:[{type:"text",text:`\u30
|
|
|
35
35
|
OAuth\u8A8D\u8A3C\u3092\u884C\u3046\u306B\u306F\u3001freee developers\u3067\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3057\u3001
|
|
36
36
|
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8ID\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};if(!p.freee.clientSecret)return{content:[{type:"text",text:`FREEE_CLIENT_SECRET\u74B0\u5883\u5909\u6570\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002
|
|
37
37
|
OAuth\u8A8D\u8A3C\u3092\u884C\u3046\u306B\u306F\u3001freee developers\u3067\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3057\u3001
|
|
38
|
-
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let{codeVerifier:e,codeChallenge:n}=
|
|
38
|
+
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let{codeVerifier:e,codeChallenge:n}=W(),i=ge.randomBytes(16).toString("hex"),a=M(n,i,A());return Z(i,e),console.error(`\u{1F310} Authentication URL: ${a}`),{content:[{type:"text",text:`\u{1F680} OAuth\u8A8D\u8A3C\u3092\u958B\u59CB\u3057\u307E\u3057\u305F\uFF01
|
|
39
39
|
|
|
40
40
|
\u{1F4F1} \u8A8D\u8A3CURL\u3092\u751F\u6210\u3057\u307E\u3057\u305F\u3002\u30D6\u30E9\u30A6\u30B6\u3067\u4EE5\u4E0B\u306EURL\u3092\u958B\u3044\u3066\u8A8D\u8A3C\u3092\u5B8C\u4E86\u3057\u3066\u304F\u3060\u3055\u3044:
|
|
41
41
|
${a}
|
|
@@ -68,21 +68,21 @@ ${a}
|
|
|
68
68
|
|
|
69
69
|
\u{1F527} \u89E3\u6C7A\u624B\u9806:
|
|
70
70
|
1. freee_status - \u5168\u4F53\u7684\u306A\u72B6\u614B\u3092\u78BA\u8A8D
|
|
71
|
-
2. freee_getting_started - \u521D\u671F\u8A2D\u5B9A\u30AC\u30A4\u30C9`}]}}}),t.tool("freee_clear_auth","freee API\u306E\u8A8D\u8A3C\u60C5\u5831\u3092\u30AF\u30EA\u30A2\u3057\u307E\u3059\u3002\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u30C8\u30FC\u30AF\u30F3\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3057\u3001\u6B21\u56DEAPI\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u306B\u306A\u308A\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30A8\u30E9\u30FC\u6642\u306E\u30EA\u30BB\u30C3\u30C8\u7528\u3011",{},async()=>{try{return await
|
|
71
|
+
2. freee_getting_started - \u521D\u671F\u8A2D\u5B9A\u30AC\u30A4\u30C9`}]}}}),t.tool("freee_clear_auth","freee API\u306E\u8A8D\u8A3C\u60C5\u5831\u3092\u30AF\u30EA\u30A2\u3057\u307E\u3059\u3002\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u30C8\u30FC\u30AF\u30F3\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3057\u3001\u6B21\u56DEAPI\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u306B\u306A\u308A\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30A8\u30E9\u30FC\u6642\u306E\u30EA\u30BB\u30C3\u30C8\u7528\u3011",{},async()=>{try{return await O(),{content:[{type:"text",text:`\u8A8D\u8A3C\u60C5\u5831\u304C\u30AF\u30EA\u30A2\u3055\u308C\u307E\u3057\u305F\u3002
|
|
72
72
|
\u6B21\u56DEfreee API\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002
|
|
73
73
|
\u518D\u8A8D\u8A3C\u3059\u308B\u306B\u306F freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u8A8D\u8A3C\u60C5\u5831\u306E\u30AF\u30EA\u30A2\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
74
74
|
|
|
75
75
|
\u{1F527} \u4EE3\u66FF\u624B\u9806:
|
|
76
76
|
1. freee_status - \u72B6\u614B\u3092\u78BA\u8A8D
|
|
77
|
-
2. \u624B\u52D5\u3067\u30D5\u30A1\u30A4\u30EB\u524A\u9664: ~/.config/freee-mcp/tokens.json`}]}}}),t.tool("freee_set_company","\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\u30FB\u5207\u308A\u66FF\u3048\u307E\u3059\u3002\u65B0\u3057\u3044\u4E8B\u696D\u6240\u306E\u5834\u5408\u306F\u81EA\u52D5\u7684\u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",{company_id:
|
|
77
|
+
2. \u624B\u52D5\u3067\u30D5\u30A1\u30A4\u30EB\u524A\u9664: ~/.config/freee-mcp/tokens.json`}]}}}),t.tool("freee_set_company","\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\u30FB\u5207\u308A\u66FF\u3048\u307E\u3059\u3002\u65B0\u3057\u3044\u4E8B\u696D\u6240\u306E\u5834\u5408\u306F\u81EA\u52D5\u7684\u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",{company_id:z.string().describe("\u4E8B\u696D\u6240ID\uFF08\u5FC5\u9808\uFF09"),name:z.string().optional().describe("\u4E8B\u696D\u6240\u540D\uFF08\u30AA\u30D7\u30B7\u30E7\u30F3\u3001\u65B0\u898F\u8FFD\u52A0\u6642\u306B\u8A2D\u5B9A\uFF09"),description:z.string().optional().describe("\u4E8B\u696D\u6240\u306E\u8AAC\u660E\uFF08\u30AA\u30D7\u30B7\u30E7\u30F3\uFF09")},async e=>{try{let{company_id:n,name:i,description:a}=e;await H(n,i,a);let r=await q(n);return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u3092\u5207\u308A\u66FF\u3048\u307E\u3057\u305F:\\n\u4E8B\u696D\u6240ID: ${n}\\n\u4E8B\u696D\u6240\u540D: ${r?.name||"Unknown"}\\n\u8AAC\u660E: ${r?.description||"\u306A\u3057"}\\n\\n\u{1F680} \u3053\u306E\u4E8B\u696D\u6240\u3067\u3059\u3050\u306BAPI\u3092\u4F7F\u7528\u3067\u304D\u307E\u3059\uFF08\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\uFF09\u3002
|
|
78
78
|
|
|
79
79
|
\u{1F4A1} \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
|
|
80
80
|
\u30FB \u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408: freee_current_user \u3067\u30C6\u30B9\u30C8
|
|
81
|
-
\u30FB \u672A\u8A8D\u8A3C\u306E\u5834\u5408: freee_authenticate \u3067\u8A8D\u8A3C`}]}}catch(n){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n instanceof Error?n.message:String(n)}`}]}}}),t.tool("freee_get_current_company","\u73FE\u5728\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u4E8B\u696D\u6240\u306E\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u3010\u73FE\u5728\u306E\u4F5C\u696D\u5BFE\u8C61\u4E8B\u696D\u6240\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await g(),n=await q(e);return n?{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240\u60C5\u5831:\\n\u4E8B\u696D\u6240ID: ${n.id}\\n\u4E8B\u696D\u6240\u540D: ${n.name}\\n\u8AAC\u660E: ${n.description||"\u306A\u3057"}\\n\u8FFD\u52A0\u65E5\u6642: ${new Date(n.addedAt).toLocaleString()}\\n\u6700\u7D42\u4F7F\u7528: ${n.lastUsed?new Date(n.lastUsed).toLocaleString():"\u306A\u3057"}`}]}:{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${e}\\n\u4E8B\u696D\u6240\u60C5\u5831\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}`}]}}}),t.tool("freee_list_companies","\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u5185\u90E8\u7684\u306Bget_companies\u3092\u547C\u3073\u51FA\u3057\u3066freee API\u304B\u3089\u6700\u65B0\u306E\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u3010\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\u524D\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await w("GET","/api/1/companies"),n=await
|
|
81
|
+
\u30FB \u672A\u8A8D\u8A3C\u306E\u5834\u5408: freee_authenticate \u3067\u8A8D\u8A3C`}]}}catch(n){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n instanceof Error?n.message:String(n)}`}]}}}),t.tool("freee_get_current_company","\u73FE\u5728\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u4E8B\u696D\u6240\u306E\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u3010\u73FE\u5728\u306E\u4F5C\u696D\u5BFE\u8C61\u4E8B\u696D\u6240\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await g(),n=await q(e);return n?{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240\u60C5\u5831:\\n\u4E8B\u696D\u6240ID: ${n.id}\\n\u4E8B\u696D\u6240\u540D: ${n.name}\\n\u8AAC\u660E: ${n.description||"\u306A\u3057"}\\n\u8FFD\u52A0\u65E5\u6642: ${new Date(n.addedAt).toLocaleString()}\\n\u6700\u7D42\u4F7F\u7528: ${n.lastUsed?new Date(n.lastUsed).toLocaleString():"\u306A\u3057"}`}]}:{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${e}\\n\u4E8B\u696D\u6240\u60C5\u5831\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}`}]}}}),t.tool("freee_list_companies","\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u5185\u90E8\u7684\u306Bget_companies\u3092\u547C\u3073\u51FA\u3057\u3066freee API\u304B\u3089\u6700\u65B0\u306E\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u3010\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\u524D\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await w("GET","/api/1/companies"),n=await k(),i=await g();if(!e||!e.companies||e.companies.length===0)return{content:[{type:"text",text:`freee API\u304B\u3089\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u8A8D\u8A3C\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
82
82
|
|
|
83
83
|
\u{1F4A1} \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
|
|
84
84
|
1. freee_auth_status - \u8A8D\u8A3C\u72B6\u614B\u3092\u78BA\u8A8D
|
|
85
|
-
2. freee_authenticate - \u8A8D\u8A3C\u3092\u5B9F\u884C`}]};let a=e.companies.map(r=>{let o=r.id===parseInt(i)?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=n.find(m=>m.id===r.id.toString()),c=s?.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(s.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${r.name} (ID: ${r.id})${o}\\n \u8AAC\u660E: ${r.description||"\u306A\u3057"}\\n ${c}`}).join("\\n\\n");return{content:[{type:"text",text:`freee API\u4E8B\u696D\u6240\u4E00\u89A7 (${e.companies.length}\u4EF6):\\n\\n${a}`}]}}catch(e){try{let n=await
|
|
85
|
+
2. freee_authenticate - \u8A8D\u8A3C\u3092\u5B9F\u884C`}]};let a=e.companies.map(r=>{let o=r.id===parseInt(i)?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=n.find(m=>m.id===r.id.toString()),c=s?.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(s.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${r.name} (ID: ${r.id})${o}\\n \u8AAC\u660E: ${r.description||"\u306A\u3057"}\\n ${c}`}).join("\\n\\n");return{content:[{type:"text",text:`freee API\u4E8B\u696D\u6240\u4E00\u89A7 (${e.companies.length}\u4EF6):\\n\\n${a}`}]}}catch(e){try{let n=await k(),i=await g();if(n.length===0)return{content:[{type:"text",text:`API\u547C\u3073\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
86
86
|
|
|
87
87
|
\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u3082\u3042\u308A\u307E\u305B\u3093\u3002freee_set_company \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u4E8B\u696D\u6240\u3092\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let a=n.map(r=>{let o=r.id===i?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=r.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(r.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${r.name} (ID: ${r.id})${o}\\n \u8AAC\u660E: ${r.description||"\u306A\u3057"}\\n ${s}`}).join("\\n\\n");return{content:[{type:"text",text:`API\u547C\u3073\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
88
88
|
|
|
@@ -205,7 +205,7 @@ freee_set_company [\u4E8B\u696D\u6240ID] # \u5207\u308A\u66FF\u3048
|
|
|
205
205
|
|
|
206
206
|
### \u4E8B\u696D\u6240ID\u304C\u5206\u304B\u3089\u306A\u3044\u5834\u5408
|
|
207
207
|
1. freee\u753B\u9762\u306EURL\u304B\u3089\u78BA\u8A8D\uFF08\u4F8B: /companies/12345/...\uFF09
|
|
208
|
-
2. \u65E2\u5B58\u306E\u8A8D\u8A3C\u304C\u3042\u308C\u3070 \`freee_current_user\` \u3067\u78BA\u8A8D\u53EF\u80FD`}]}}catch(e){return{content:[{type:"text",text:`\u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9\u306E\u8868\u793A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u307E\u305A\u306F\u74B0\u5883\u5909\u6570\u306E\u8A2D\u5B9A\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044\u3002`}]}}}),t.tool("freee_status","\u73FE\u5728\u306Efreee MCP \u30B5\u30FC\u30D0\u30FC\u306E\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3001\u6B21\u306B\u5B9F\u884C\u3059\u3079\u304D\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u63D0\u6848\u3057\u307E\u3059\u3002",{},async()=>{try{let e=await g(),n=await q(e),i=await I(),a=await
|
|
208
|
+
2. \u65E2\u5B58\u306E\u8A8D\u8A3C\u304C\u3042\u308C\u3070 \`freee_current_user\` \u3067\u78BA\u8A8D\u53EF\u80FD`}]}}catch(e){return{content:[{type:"text",text:`\u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9\u306E\u8868\u793A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u307E\u305A\u306F\u74B0\u5883\u5909\u6570\u306E\u8A2D\u5B9A\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044\u3002`}]}}}),t.tool("freee_status","\u73FE\u5728\u306Efreee MCP \u30B5\u30FC\u30D0\u30FC\u306E\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3001\u6B21\u306B\u5B9F\u884C\u3059\u3079\u304D\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u63D0\u6848\u3057\u307E\u3059\u3002",{},async()=>{try{let e=await g(),n=await q(e),i=await I(),a=await k(),r="",o="",s="";if(!e||e==="0"?(r+="\u274C **\u4E8B\u696D\u6240**: \u672A\u8A2D\u5B9A\\n",o+="\u2022 freee_set_company [\u4E8B\u696D\u6240ID] \u3067\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\\n"):n?r+=`\u2705 **\u4E8B\u696D\u6240**: ${n.name} (ID: ${n.id})\\n`:(r+="\u26A0\uFE0F **\u4E8B\u696D\u6240**: \u8A2D\u5B9A\u4E0D\u5B8C\u5168\\n",o+="\u2022 freee_set_company \u3067\u4E8B\u696D\u6240\u60C5\u5831\u3092\u518D\u8A2D\u5B9A\\n"),!i)r+="\u274C **\u8A8D\u8A3C**: \u672A\u8A8D\u8A3C\\n",o+="\u2022 freee_authenticate \u3067\u8A8D\u8A3C\u3092\u5B9F\u884C\\n";else{let c=Date.now()<i.expires_at,m=new Date(i.expires_at).toLocaleString();c?(r+=`\u2705 **\u8A8D\u8A3C**: \u6709\u52B9 (\u671F\u9650: ${m})\\n`,o+="\u2022 freee_current_user \u3067\u30C6\u30B9\u30C8\u5B9F\u884C\\n\u2022 get_deals, get_companies \u306A\u3069\u306EAPI\u30C4\u30FC\u30EB\u304C\u4F7F\u7528\u53EF\u80FD\\n"):(r+=`\u26A0\uFE0F **\u8A8D\u8A3C**: \u671F\u9650\u5207\u308C (${m})\\n`,o+="\u2022 \u6B21\u56DEAPI\u5B9F\u884C\u6642\u306B\u81EA\u52D5\u66F4\u65B0\u3055\u308C\u307E\u3059\\n\u2022 \u624B\u52D5\u66F4\u65B0: freee_authenticate\\n")}return r+=`\u{1F4CA} **\u767B\u9332\u4E8B\u696D\u6240\u6570**: ${a.length}\u4EF6\\n`,a.length>1?o+="\u2022 freee_list_companies \u3067\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u78BA\u8A8D\\n\u2022 freee_set_company [ID] \u3067\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\\n":a.length===1&&(o+="\u2022 freee_set_company [\u65B0\u3057\u3044ID] \u3067\u8FFD\u52A0\u4E8B\u696D\u6240\u3092\u767B\u9332\u53EF\u80FD\\n"),(!p.freee.clientId||!p.freee.clientSecret)&&(s+="\u26A0\uFE0F **\u74B0\u5883\u5909\u6570**: FREEE_CLIENT_ID \u307E\u305F\u306F FREEE_CLIENT_SECRET \u304C\u672A\u8A2D\u5B9A\\n"),e&&n&&i&&Date.now()<i.expires_at&&(o+="\\n\u{1F680} **\u3059\u3050\u306B\u4F7F\u7528\u53EF\u80FD**: freee API\u30C4\u30FC\u30EB\u304C\u5229\u7528\u3067\u304D\u307E\u3059\\n",o+="**\u4F8B**: get_deals, get_companies, get_users, \u306A\u3069"),{content:[{type:"text",text:`# freee MCP \u30B5\u30FC\u30D0\u30FC \u72B6\u614B\u78BA\u8A8D
|
|
209
209
|
|
|
210
210
|
## \u{1F4CA} \u73FE\u5728\u306E\u72B6\u614B
|
|
211
211
|
${r}
|
|
@@ -218,7 +218,7 @@ ${o}
|
|
|
218
218
|
- \`freee_help\` - \u5168\u4F53\u7684\u306A\u4F7F\u3044\u65B9\u30AC\u30A4\u30C9
|
|
219
219
|
- \`freee_getting_started\` - \u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9
|
|
220
220
|
- \`freee_list_companies\` - \u4E8B\u696D\u6240\u4E00\u89A7
|
|
221
|
-
- \`freee_auth_status\` - \u8A8D\u8A3C\u72B6\u614B\u306E\u8A73\u7D30`}]}}catch(e){return{content:[{type:"text",text:`\u72B6\u614B\u78BA\u8A8D\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u57FA\u672C\u7684\u306A\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044:\\n1. freee_getting_started\\n2. freee_set_company [\u4E8B\u696D\u6240ID]\\n3. freee_authenticate`}]}}})}import{z as
|
|
221
|
+
- \`freee_auth_status\` - \u8A8D\u8A3C\u72B6\u614B\u306E\u8A73\u7D30`}]}}catch(e){return{content:[{type:"text",text:`\u72B6\u614B\u78BA\u8A8D\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u57FA\u672C\u7684\u306A\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044:\\n1. freee_getting_started\\n2. freee_set_company [\u4E8B\u696D\u6240ID]\\n3. freee_authenticate`}]}}})}import{z as fe}from"zod";var Q={openapi:"3.0.1",info:{title:"freee\u4F1A\u8A08 API",description:`
|
|
222
222
|
<hr />
|
|
223
223
|
<h2 id="start_guide">\u30B9\u30BF\u30FC\u30C8\u30AC\u30A4\u30C9</h2>
|
|
224
224
|
|
|
@@ -4987,4 +4987,4 @@ submitted \u306F\u8ACB\u6C42\u66F8\u627F\u8A8D\u30EF\u30FC\u30AF\u30D5\u30ED\u30
|
|
|
4987
4987
|
<ul>
|
|
4988
4988
|
<li>normal\u3001discount\u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u3001account_item_id,tax_code\u3068unit_price\u304C\u5FC5\u9808\u3068\u306A\u308A\u307E\u3059\u3002</li>
|
|
4989
4989
|
<li>normal\u3092\u6307\u5B9A\u3057\u305F\u5834\u5408\u3001qty\u304C\u5FC5\u9808\u3068\u306A\u308A\u307E\u3059\u3002</li>
|
|
4990
|
-
</ul>`,example:"normal",enum:["normal","discount","text"]},qty:{type:"number",minimum:0,maximum:99999999,description:"\u6570\u91CF",example:1},unit:{type:"string",description:"\u5358\u4F4D",example:"\u500B"},unit_price:{type:"number",minimum:-999999999999,maximum:999999999999,description:"\u5358\u4FA1 (tax_entry_method: inclusive\u306E\u5834\u5408\u306F\u7A0E\u8FBC\u4FA1\u683C\u3001tax_entry_method: exclusive\u306E\u5834\u5408\u306F\u7A0E\u629C\u4FA1\u683C\u3068\u306A\u308A\u307E\u3059)",example:1},vat:{type:"integer",format:"int64",nullable:!0,description:"\u6D88\u8CBB\u7A0E\u984D",example:8e3},description:{type:"string",description:"\u5099\u8003",example:"\u5099\u8003"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},tax_code:{type:"integer",format:"int64",minimum:0,maximum:2147483647,description:"\u7A0E\u533A\u5206\u30B3\u30FC\u30C9",example:1},item_id:{type:"integer",format:"int64",minimum:1,description:"\u54C1\u76EEID",example:1},section_id:{type:"integer",format:"int64",minimum:1,description:"\u90E8\u9580ID",example:1},tag_ids:{type:"array",items:{type:"integer",format:"int64",minimum:1,description:"\u30E1\u30E2\u30BF\u30B0ID",example:1}},segment_1_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF11\u30BF\u30B0ID",example:1},segment_2_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF12\u30BF\u30B0ID",example:1},segment_3_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF13\u30BF\u30B0ID",example:1}}}}}},fixedAssetResponse:{type:"object",required:["fixed_assets","fiscal_year","up_to_date","up_to_date_reasons"],properties:{fixed_assets:{type:"array",items:{type:"object",properties:{company_id:{type:"integer",format:"int64",minimum:1,description:"\u4E8B\u696D\u6240ID",example:1},id:{type:"integer",format:"int64",minimum:1,description:"\u56FA\u5B9A\u8CC7\u7523ID",example:1},name:{type:"string",description:"\u56FA\u5B9A\u8CC7\u7523\u540D",example:"pc"},management_number:{type:"string",nullable:!0,description:"\u7BA1\u7406\u756A\u53F7",example:"pc-0001"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:22},section_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u90E8\u9580ID",example:0},item_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u54C1\u76EEID",example:0},depreciation_method:{type:"string",description:"\u511F\u5374\u65B9\u6CD5:(\u5C11\u984D\u511F\u5374: small_sum_method, \u4E00\u62EC\u511F\u5374: lump_sum_method, \u5B9A\u984D\u6CD5: straight_line_method, \u5B9A\u7387\u6CD5: multiple_method, \u65E7\u5B9A\u7387\u6CD5: old_multiple_method, \u65E7\u5B9A\u984D\u6CD5: old_straight_line_method, \u511F\u5374\u306A\u3057: non_depreciate_method, \u4EFB\u610F\u511F\u5374: voluntary_method, \u5373\u6642\u511F\u5374: immediate_method, \u5747\u7B49\u511F\u5374: equal_method)",enum:["small_sum_method","lump_sum_method","straight_line_method","multiple_method","old_multiple_method","old_straight_line_method","non_depreciate_method","voluntary_method","immediate_method","equal_method"],example:"straight_line_method"},depreciation_account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u6E1B\u4FA1\u511F\u5374\u306B\u4F7F\u3046\u52D8\u5B9A\u79D1\u76EEID",example:99},prefecture_code:{type:"integer",format:"int64",minimum:-1,maximum:46,description:"\u90FD\u9053\u5E9C\u770C\u30B3\u30FC\u30C9\uFF08-1: \u8A2D\u5B9A\u3057\u306A\u3044\u30010:\u5317\u6D77\u9053\u30011:\u9752\u68EE\u30012:\u5CA9\u624B\u30013:\u5BAE\u57CE\u30014:\u79CB\u7530\u30015:\u5C71\u5F62\u30016:\u798F\u5CF6\u30017:\u8328\u57CE\u30018:\u6803\u6728\u30019:\u7FA4\u99AC\u300110:\u57FC\u7389\u300111:\u5343\u8449\u300112:\u6771\u4EAC\u300113:\u795E\u5948\u5DDD\u300114:\u65B0\u6F5F\u300115:\u5BCC\u5C71\u300116:\u77F3\u5DDD\u300117:\u798F\u4E95\u300118:\u5C71\u68A8\u300119:\u9577\u91CE\u300120:\u5C90\u961C\u300121:\u9759\u5CA1\u300122:\u611B\u77E5\u300123:\u4E09\u91CD\u300124:\u6ECB\u8CC0\u300125:\u4EAC\u90FD\u300126:\u5927\u962A\u300127:\u5175\u5EAB\u300128:\u5948\u826F\u300129:\u548C\u6B4C\u5C71\u300130:\u9CE5\u53D6\u300131:\u5CF6\u6839\u300132:\u5CA1\u5C71\u300133:\u5E83\u5CF6\u300134:\u5C71\u53E3\u300135:\u5FB3\u5CF6\u300136:\u9999\u5DDD\u300137:\u611B\u5A9B\u300138:\u9AD8\u77E5\u300139:\u798F\u5CA1\u300140:\u4F50\u8CC0\u300141:\u9577\u5D0E\u300142:\u718A\u672C\u300143:\u5927\u5206\u300144:\u5BAE\u5D0E\u300145:\u9E7F\u5150\u5CF6\u300146:\u6C96\u7E04",example:4,nullable:!0},city_name:{type:"string",nullable:!0,description:"\u7533\u544A\u5148\u5E02\u533A\u753A\u6751",example:"\u6E2F\u533A"},depreciation_amount:{type:"integer",format:"int64",description:"\u672C\u5E74\u5206\u306E\u511F\u5374\u8CBB\u5408\u8A08",example:"18533"},acquisition_cost:{type:"integer",format:"int64",description:"\u53D6\u5F97\u4FA1\u984D",example:"150000"},opening_balance:{type:"integer",format:"int64",description:"\u671F\u9996\u6B8B\u9AD8\uFF08\u53D6\u5F97\u65E5\u304C\u4F1A\u8A08\u671F\u9593\u306B\u542B\u307E\u308C\u308B\u3068\u304D\u671F\u9996\u6B8B\u9AD8\u306F0\u306B\u306A\u308A\u307E\u3059\u3002\uFF09",example:"92000"},undepreciated_balance:{type:"integer",format:"int64",description:"\u672A\u511F\u5374\u6B8B\u9AD8",example:"46000"},opening_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u9996\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"100000"},closing_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u672B\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"46000"},life_years:{type:"integer",format:"int64",description:"\u8010\u7528\u5E74\u6570",example:"5"},acquisition_date:{type:"string",description:"\u53D6\u5F97\u65E5",format:"date",example:"2021-07-13"},created_at:{type:"string",description:"\u4F5C\u6210\u65E5\u6642\uFF08ISO8601\u5F62\u5F0F\uFF09",example:"2021-07-15T18:30:24+09:00"},depreciation_status:{type:"string",description:"\u58F2\u5374\u3082\u3057\u304F\u306F\u9664\u5374\u30B9\u30C6\u30FC\u30BF\u30B9: (\u58F2\u5374\u6E08: sold, \u9664\u5374\u6E08: retired, \u511F\u5374\u6E08: depreciated, \u511F\u5374\u4E2D: depreciation, \u511F\u5374\u306A\u3057: non_depreciation)",enum:["sold","retired","depreciated","depreciation","non_depreciation"],example:"depreciation"},retire_date:{type:"string",format:"date",nullable:!0,description:"\u9664\u5374\u65E5\u3001\u3082\u3057\u304F\u306F\u58F2\u5374\u65E5",example:"2022-03-24"}}}},fiscal_year:{type:"object",required:["start_date","end_date"],properties:{start_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u958B\u59CB\u65E5 (yyyy-mm-dd)",example:"2022-01-01"},end_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u7D42\u4E86\u65E5 (yyyy-mm-dd)",example:"2022-12-31"}}},up_to_date:{type:"boolean",description:"\u96C6\u8A08\u7D50\u679C\u304C\u6700\u65B0\u304B\u3069\u3046\u304B",example:!0},up_to_date_reasons:{type:"array",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u5834\u5408\u306E\u8981\u56E0\u60C5\u5831",items:{type:"object",required:["code","message"],properties:{code:{type:"string",description:"\u30B3\u30FC\u30C9",example:"depreciation_creating",enum:["depreciation_creating","depreciation_create_error"]},message:{type:"string",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u7406\u7531",example:"\u5F53\u671F\u306E\u56FA\u5B9A\u8CC7\u7523\u306E\u511F\u5374\u4F5C\u6210\u304C\u5B8C\u4E86\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6B63\u3057\u3044\u96C6\u8A08\u7D50\u679C\u3067\u306A\u3044\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002"}}}}}},generalLedgersResponse:{type:"object",required:["general_ledgers"],properties:{general_ledgers:{type:"array",items:{type:"object",properties:{account_item_id:{type:"integer",format:"int64",description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},account_item_name:{type:"string",description:"\u52D8\u5B9A\u79D1\u76EE\u540D",example:"\u58F2\u639B\u91D1"},total_amount:{type:"integer",format:"int64",description:"\u767A\u751F\u984D\u7D2F\u8A08",example:100},final_balance:{type:"integer",format:"int64",description:"\u6B8B\u9AD8",example:100},debit_amount:{type:"integer",format:"int64",description:"\u501F\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100},credit_amount:{type:"integer",format:"int64",description:"\u8CB8\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100}}}}}},accountGroupCreateParams:{type:"object",required:["company_id","name","account_category_id"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",format:"int64",example:1},name:{type:"string",maxLength:20,description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D (20\u6587\u5B57\u4EE5\u5185)",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EA\u30FCID Selectables\u30D5\u30A9\u30FC\u30E0\u7528\u9078\u629E\u9805\u76EE\u60C5\u5831\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8(account_groups.account_category_id)\u3067\u53D6\u5F97\u53EF\u80FD\u3067\u3059",format:"int64",example:1},index:{type:"integer",description:"\u8868\u793A\u9806",format:"int64",example:1}}},accountGroupCreateResponse:{type:"object",required:["account_group"],properties:{account_group:{type:"object",required:["company_id","id","name","account_structure_id","account_category_id","index"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",example:1,format:"int64"},id:{type:"integer",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D(\u5C0F\u30AB\u30C6\u30B4\u30EA\u30FC)ID",example:1,format:"int64"},name:{type:"string",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_structure_id:{type:"integer",description:"\u5E74\u5EA6ID",example:1,format:"int64"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EAID",example:1,format:"int64"},index:{type:"integer",description:"\u8868\u793A\u9806",example:1,format:"int64"}}}}}},securitySchemes:{oauth2:{type:"oauth2",flows:{authorizationCode:{authorizationUrl:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenUrl:"https://accounts.secure.freee.co.jp/public_api/token",scopes:{write:"\u30C7\u30FC\u30BF\u306E\u66F8\u304D\u8FBC\u307F",read:"\u30C7\u30FC\u30BF\u306E\u8AAD\u307F\u53D6\u308A"}}}}}}};import{z as D}from"zod";function L(t){let{type:e}=t.schema||t,{description:n,required:i}=t,a;switch(e){case"string":a=D.string();break;case"integer":a=D.number().int();break;case"number":a=D.number();break;case"boolean":a=D.boolean();break;default:a=D.any()}return n&&(a=a.describe(n)),i||(a=a.optional()),a}function K(t){let e=t.replace(/^\/api\/\d+\//,"").replace(/\/{[^}]+}/g,"_by_id").replace(/\//g,"_");return e.length>50&&(e=e.substring(0,50)),e}function Q(t){let e=H.paths;Object.keys(e).sort().forEach(i=>{let a=e[i];Object.entries(a).forEach(([r,o])=>{let s=`${r}_${K(i)}`,c=o.summary||o.description||"",m={},d=o.parameters?.filter(l=>l.in==="path")||[];d.forEach(l=>{m[l.name]=L(l)});let x=o.parameters?.filter(l=>l.in==="query")||[];x.forEach(l=>{let u=L(l);l.name==="company_id"&&(u=u.optional()),m[l.name]=u});let j=ye.any();(r==="post"||r==="put")&&o.requestBody?.content?.["application/json"]?.schema&&(m.body=j.describe("Request body")),t.tool(s,c,m,async l=>{try{let u=i;d.forEach(b=>{u=u.replace(`{${b.name}}`,String(l[b.name]))});let z={};x.forEach(b=>{l[b.name]!==void 0&&(z[b.name]=l[b.name])});let ee=r==="post"||r==="put"?l.body:void 0,te=await w(r.toUpperCase(),u,z,ee);return{content:[{type:"text",text:JSON.stringify(te,null,2)}]}}catch(u){return{content:[{type:"text",text:`Error: ${u instanceof Error?u.message:String(u)}`}]}}})})})}async function X(){let t=new ge({name:p.server.name,version:p.server.version});Y(t),Q(t);try{await M(),console.error(`\u2705 OAuth callback server started on http://127.0.0.1:${p.oauth.callbackPort}`)}catch(n){console.error("\u26A0\uFE0F Failed to start callback server:",n),console.error("OAuth authentication will fall back to manual mode")}let e=new he;await t.connect(e),console.error("Freee MCP Server running on stdio"),process.on("SIGINT",()=>{P(),process.exit(0)}),process.on("SIGTERM",()=>{P(),process.exit(0)})}var fe=async()=>{await X()};fe().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|
|
4990
|
+
</ul>`,example:"normal",enum:["normal","discount","text"]},qty:{type:"number",minimum:0,maximum:99999999,description:"\u6570\u91CF",example:1},unit:{type:"string",description:"\u5358\u4F4D",example:"\u500B"},unit_price:{type:"number",minimum:-999999999999,maximum:999999999999,description:"\u5358\u4FA1 (tax_entry_method: inclusive\u306E\u5834\u5408\u306F\u7A0E\u8FBC\u4FA1\u683C\u3001tax_entry_method: exclusive\u306E\u5834\u5408\u306F\u7A0E\u629C\u4FA1\u683C\u3068\u306A\u308A\u307E\u3059)",example:1},vat:{type:"integer",format:"int64",nullable:!0,description:"\u6D88\u8CBB\u7A0E\u984D",example:8e3},description:{type:"string",description:"\u5099\u8003",example:"\u5099\u8003"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},tax_code:{type:"integer",format:"int64",minimum:0,maximum:2147483647,description:"\u7A0E\u533A\u5206\u30B3\u30FC\u30C9",example:1},item_id:{type:"integer",format:"int64",minimum:1,description:"\u54C1\u76EEID",example:1},section_id:{type:"integer",format:"int64",minimum:1,description:"\u90E8\u9580ID",example:1},tag_ids:{type:"array",items:{type:"integer",format:"int64",minimum:1,description:"\u30E1\u30E2\u30BF\u30B0ID",example:1}},segment_1_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF11\u30BF\u30B0ID",example:1},segment_2_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF12\u30BF\u30B0ID",example:1},segment_3_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF13\u30BF\u30B0ID",example:1}}}}}},fixedAssetResponse:{type:"object",required:["fixed_assets","fiscal_year","up_to_date","up_to_date_reasons"],properties:{fixed_assets:{type:"array",items:{type:"object",properties:{company_id:{type:"integer",format:"int64",minimum:1,description:"\u4E8B\u696D\u6240ID",example:1},id:{type:"integer",format:"int64",minimum:1,description:"\u56FA\u5B9A\u8CC7\u7523ID",example:1},name:{type:"string",description:"\u56FA\u5B9A\u8CC7\u7523\u540D",example:"pc"},management_number:{type:"string",nullable:!0,description:"\u7BA1\u7406\u756A\u53F7",example:"pc-0001"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:22},section_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u90E8\u9580ID",example:0},item_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u54C1\u76EEID",example:0},depreciation_method:{type:"string",description:"\u511F\u5374\u65B9\u6CD5:(\u5C11\u984D\u511F\u5374: small_sum_method, \u4E00\u62EC\u511F\u5374: lump_sum_method, \u5B9A\u984D\u6CD5: straight_line_method, \u5B9A\u7387\u6CD5: multiple_method, \u65E7\u5B9A\u7387\u6CD5: old_multiple_method, \u65E7\u5B9A\u984D\u6CD5: old_straight_line_method, \u511F\u5374\u306A\u3057: non_depreciate_method, \u4EFB\u610F\u511F\u5374: voluntary_method, \u5373\u6642\u511F\u5374: immediate_method, \u5747\u7B49\u511F\u5374: equal_method)",enum:["small_sum_method","lump_sum_method","straight_line_method","multiple_method","old_multiple_method","old_straight_line_method","non_depreciate_method","voluntary_method","immediate_method","equal_method"],example:"straight_line_method"},depreciation_account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u6E1B\u4FA1\u511F\u5374\u306B\u4F7F\u3046\u52D8\u5B9A\u79D1\u76EEID",example:99},prefecture_code:{type:"integer",format:"int64",minimum:-1,maximum:46,description:"\u90FD\u9053\u5E9C\u770C\u30B3\u30FC\u30C9\uFF08-1: \u8A2D\u5B9A\u3057\u306A\u3044\u30010:\u5317\u6D77\u9053\u30011:\u9752\u68EE\u30012:\u5CA9\u624B\u30013:\u5BAE\u57CE\u30014:\u79CB\u7530\u30015:\u5C71\u5F62\u30016:\u798F\u5CF6\u30017:\u8328\u57CE\u30018:\u6803\u6728\u30019:\u7FA4\u99AC\u300110:\u57FC\u7389\u300111:\u5343\u8449\u300112:\u6771\u4EAC\u300113:\u795E\u5948\u5DDD\u300114:\u65B0\u6F5F\u300115:\u5BCC\u5C71\u300116:\u77F3\u5DDD\u300117:\u798F\u4E95\u300118:\u5C71\u68A8\u300119:\u9577\u91CE\u300120:\u5C90\u961C\u300121:\u9759\u5CA1\u300122:\u611B\u77E5\u300123:\u4E09\u91CD\u300124:\u6ECB\u8CC0\u300125:\u4EAC\u90FD\u300126:\u5927\u962A\u300127:\u5175\u5EAB\u300128:\u5948\u826F\u300129:\u548C\u6B4C\u5C71\u300130:\u9CE5\u53D6\u300131:\u5CF6\u6839\u300132:\u5CA1\u5C71\u300133:\u5E83\u5CF6\u300134:\u5C71\u53E3\u300135:\u5FB3\u5CF6\u300136:\u9999\u5DDD\u300137:\u611B\u5A9B\u300138:\u9AD8\u77E5\u300139:\u798F\u5CA1\u300140:\u4F50\u8CC0\u300141:\u9577\u5D0E\u300142:\u718A\u672C\u300143:\u5927\u5206\u300144:\u5BAE\u5D0E\u300145:\u9E7F\u5150\u5CF6\u300146:\u6C96\u7E04",example:4,nullable:!0},city_name:{type:"string",nullable:!0,description:"\u7533\u544A\u5148\u5E02\u533A\u753A\u6751",example:"\u6E2F\u533A"},depreciation_amount:{type:"integer",format:"int64",description:"\u672C\u5E74\u5206\u306E\u511F\u5374\u8CBB\u5408\u8A08",example:"18533"},acquisition_cost:{type:"integer",format:"int64",description:"\u53D6\u5F97\u4FA1\u984D",example:"150000"},opening_balance:{type:"integer",format:"int64",description:"\u671F\u9996\u6B8B\u9AD8\uFF08\u53D6\u5F97\u65E5\u304C\u4F1A\u8A08\u671F\u9593\u306B\u542B\u307E\u308C\u308B\u3068\u304D\u671F\u9996\u6B8B\u9AD8\u306F0\u306B\u306A\u308A\u307E\u3059\u3002\uFF09",example:"92000"},undepreciated_balance:{type:"integer",format:"int64",description:"\u672A\u511F\u5374\u6B8B\u9AD8",example:"46000"},opening_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u9996\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"100000"},closing_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u672B\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"46000"},life_years:{type:"integer",format:"int64",description:"\u8010\u7528\u5E74\u6570",example:"5"},acquisition_date:{type:"string",description:"\u53D6\u5F97\u65E5",format:"date",example:"2021-07-13"},created_at:{type:"string",description:"\u4F5C\u6210\u65E5\u6642\uFF08ISO8601\u5F62\u5F0F\uFF09",example:"2021-07-15T18:30:24+09:00"},depreciation_status:{type:"string",description:"\u58F2\u5374\u3082\u3057\u304F\u306F\u9664\u5374\u30B9\u30C6\u30FC\u30BF\u30B9: (\u58F2\u5374\u6E08: sold, \u9664\u5374\u6E08: retired, \u511F\u5374\u6E08: depreciated, \u511F\u5374\u4E2D: depreciation, \u511F\u5374\u306A\u3057: non_depreciation)",enum:["sold","retired","depreciated","depreciation","non_depreciation"],example:"depreciation"},retire_date:{type:"string",format:"date",nullable:!0,description:"\u9664\u5374\u65E5\u3001\u3082\u3057\u304F\u306F\u58F2\u5374\u65E5",example:"2022-03-24"}}}},fiscal_year:{type:"object",required:["start_date","end_date"],properties:{start_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u958B\u59CB\u65E5 (yyyy-mm-dd)",example:"2022-01-01"},end_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u7D42\u4E86\u65E5 (yyyy-mm-dd)",example:"2022-12-31"}}},up_to_date:{type:"boolean",description:"\u96C6\u8A08\u7D50\u679C\u304C\u6700\u65B0\u304B\u3069\u3046\u304B",example:!0},up_to_date_reasons:{type:"array",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u5834\u5408\u306E\u8981\u56E0\u60C5\u5831",items:{type:"object",required:["code","message"],properties:{code:{type:"string",description:"\u30B3\u30FC\u30C9",example:"depreciation_creating",enum:["depreciation_creating","depreciation_create_error"]},message:{type:"string",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u7406\u7531",example:"\u5F53\u671F\u306E\u56FA\u5B9A\u8CC7\u7523\u306E\u511F\u5374\u4F5C\u6210\u304C\u5B8C\u4E86\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6B63\u3057\u3044\u96C6\u8A08\u7D50\u679C\u3067\u306A\u3044\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002"}}}}}},generalLedgersResponse:{type:"object",required:["general_ledgers"],properties:{general_ledgers:{type:"array",items:{type:"object",properties:{account_item_id:{type:"integer",format:"int64",description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},account_item_name:{type:"string",description:"\u52D8\u5B9A\u79D1\u76EE\u540D",example:"\u58F2\u639B\u91D1"},total_amount:{type:"integer",format:"int64",description:"\u767A\u751F\u984D\u7D2F\u8A08",example:100},final_balance:{type:"integer",format:"int64",description:"\u6B8B\u9AD8",example:100},debit_amount:{type:"integer",format:"int64",description:"\u501F\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100},credit_amount:{type:"integer",format:"int64",description:"\u8CB8\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100}}}}}},accountGroupCreateParams:{type:"object",required:["company_id","name","account_category_id"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",format:"int64",example:1},name:{type:"string",maxLength:20,description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D (20\u6587\u5B57\u4EE5\u5185)",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EA\u30FCID Selectables\u30D5\u30A9\u30FC\u30E0\u7528\u9078\u629E\u9805\u76EE\u60C5\u5831\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8(account_groups.account_category_id)\u3067\u53D6\u5F97\u53EF\u80FD\u3067\u3059",format:"int64",example:1},index:{type:"integer",description:"\u8868\u793A\u9806",format:"int64",example:1}}},accountGroupCreateResponse:{type:"object",required:["account_group"],properties:{account_group:{type:"object",required:["company_id","id","name","account_structure_id","account_category_id","index"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",example:1,format:"int64"},id:{type:"integer",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D(\u5C0F\u30AB\u30C6\u30B4\u30EA\u30FC)ID",example:1,format:"int64"},name:{type:"string",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_structure_id:{type:"integer",description:"\u5E74\u5EA6ID",example:1,format:"int64"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EAID",example:1,format:"int64"},index:{type:"integer",description:"\u8868\u793A\u9806",example:1,format:"int64"}}}}}},securitySchemes:{oauth2:{type:"oauth2",flows:{authorizationCode:{authorizationUrl:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenUrl:"https://accounts.secure.freee.co.jp/public_api/token",scopes:{write:"\u30C7\u30FC\u30BF\u306E\u66F8\u304D\u8FBC\u307F",read:"\u30C7\u30FC\u30BF\u306E\u8AAD\u307F\u53D6\u308A"}}}}}}};import{z as D}from"zod";function N(t){let{type:e}=t.schema||t,{description:n,required:i}=t,a;switch(e){case"string":a=D.string();break;case"integer":a=D.number().int();break;case"number":a=D.number();break;case"boolean":a=D.boolean();break;default:a=D.any()}return n&&(a=a.describe(n)),i||(a=a.optional()),a}function X(t){let e=t.replace(/^\/api\/\d+\//,"").replace(/\/{[^}]+}/g,"_by_id").replace(/\//g,"_");return e.length>50&&(e=e.substring(0,50)),e}function ee(t){let e=Q.paths;Object.keys(e).sort().forEach(i=>{let a=e[i];Object.entries(a).forEach(([r,o])=>{let s=`${r}_${X(i)}`,c=o.summary||o.description||"",m={},d=o.parameters?.filter(l=>l.in==="path")||[];d.forEach(l=>{m[l.name]=N(l)});let x=o.parameters?.filter(l=>l.in==="query")||[];x.forEach(l=>{let u=N(l);l.name==="company_id"&&(u=u.optional()),m[l.name]=u});let j=fe.any();(r==="post"||r==="put")&&o.requestBody?.content?.["application/json"]?.schema&&(m.body=j.describe("Request body")),t.tool(s,c,m,async l=>{try{let u=i;d.forEach(b=>{u=u.replace(`{${b.name}}`,String(l[b.name]))});let F={};x.forEach(b=>{l[b.name]!==void 0&&(F[b.name]=l[b.name])});let ne=r==="post"||r==="put"?l.body:void 0,ie=await w(r.toUpperCase(),u,F,ne);return{content:[{type:"text",text:JSON.stringify(ie,null,2)}]}}catch(u){return{content:[{type:"text",text:`Error: ${u instanceof Error?u.message:String(u)}`}]}}})})})}async function te(){let t=new xe({name:p.server.name,version:p.server.version});K(t),ee(t);try{await V(),console.error(`\u2705 OAuth callback server started on http://127.0.0.1:${p.oauth.callbackPort}`)}catch(n){console.error("\u26A0\uFE0F Failed to start callback server:",n),console.error("OAuth authentication will fall back to manual mode")}let e=new be;await t.connect(e),console.error("Freee MCP Server running on stdio"),process.on("SIGINT",()=>{T(),process.exit(0)}),process.on("SIGTERM",()=>{T(),process.exit(0)})}var qe=async()=>{await te()};qe().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|
package/dist/auth/oauth.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare function generatePKCE(): {
|
|
|
4
4
|
codeChallenge: string;
|
|
5
5
|
};
|
|
6
6
|
export declare function buildAuthUrl(codeChallenge: string, state: string, redirectUri: string): string;
|
|
7
|
-
export declare function exchangeCodeForTokens(code: string, codeVerifier: string): Promise<TokenData>;
|
|
7
|
+
export declare function exchangeCodeForTokens(code: string, codeVerifier: string, redirectUri: string): Promise<TokenData>;
|
package/dist/auth/server.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare function getActualRedirectUri(): string;
|
|
2
|
+
export declare function getActualCallbackPort(): number | null;
|
|
1
3
|
export declare function startCallbackServer(): Promise<void>;
|
|
2
4
|
export declare function registerAuthenticationRequest(state: string, codeVerifier: string): void;
|
|
3
5
|
export declare function stopCallbackServer(): void;
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var de=Object.create;var U=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var he=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of _e(e))!ge.call(t,r)&&r!==n&&U(t,r,{get:()=>e[r],enumerable:!(i=ue(e,r))||i.enumerable});return t};var y=(t,e,n)=>(n=t!=null?de(ye(t)):{},he(e||!t||!t.__esModule?U(n,"default",{value:t,enumerable:!0}):n,t));var pe=require("@modelcontextprotocol/sdk/server/mcp.js"),se=require("@modelcontextprotocol/sdk/server/stdio.js");var O=parseInt(process.env.FREEE_CALLBACK_PORT||"8080",10),p={freee:{clientId:process.env.FREEE_CLIENT_ID||"",clientSecret:process.env.FREEE_CLIENT_SECRET||"",companyId:process.env.FREEE_COMPANY_ID||"0",apiUrl:"https://api.freee.co.jp"},oauth:{callbackPort:O,redirectUri:`http://127.0.0.1:${O}/callback`,authorizationEndpoint:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenEndpoint:"https://accounts.secure.freee.co.jp/public_api/token",scope:"read write"},server:{name:"freee",version:"1.0.0"},auth:{timeoutMs:5*60*1e3}};var V=y(require("http"),1),Z=require("url"),Y=y(require("net"),1);var C=y(require("crypto"),1);var g=y(require("fs/promises"),1),h=y(require("path"),1),$=y(require("os"),1);function S(){let t=h.default.join($.default.homedir(),".config","freee-mcp");return h.default.join(t,"tokens.json")}async function E(t){let e=S(),n=h.default.dirname(e);try{console.error(`\u{1F4C1} Creating directory: ${n}`),await g.default.mkdir(n,{recursive:!0}),console.error(`\u{1F4BE} Writing tokens to: ${e}`),await g.default.writeFile(e,JSON.stringify(t,null,2),{mode:384}),console.error("\u2705 Tokens saved successfully")}catch(i){throw console.error("\u274C Failed to save tokens:",i),i}}async function D(){let t=S();try{let e=await g.default.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=await xe();return n||null}throw console.error("Failed to load tokens:",e),e}}function fe(t){return Date.now()<t.expires_at}async function xe(){let t=h.default.join($.default.homedir(),".config","freee-mcp");try{let n=(await g.default.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));if(n.length>0){let i=h.default.join(t,n[0]),r=await g.default.readFile(i,"utf8"),a=JSON.parse(r);return await E(a),await Promise.all(n.map(o=>g.default.unlink(h.default.join(t,o)).catch(()=>{}))),console.error("\u2705 Migrated legacy company-specific tokens to user-based tokens"),a}}catch{}return null}async function be(t){let e=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:p.freee.clientId,client_secret:p.freee.clientSecret})});if(!e.ok){let r=await e.json().catch(()=>({}));throw new Error(`Token refresh failed: ${e.status} ${JSON.stringify(r)}`)}let n=await e.json(),i={access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+n.expires_in*1e3,token_type:n.token_type||"Bearer",scope:n.scope||p.oauth.scope};return await E(i),i}async function J(){let t=S();try{await g.default.unlink(t),console.error("Tokens cleared successfully")}catch(e){if(e.code==="ENOENT"){console.error("No tokens to clear (file does not exist)");return}throw console.error("Failed to clear tokens:",e),e}await qe()}async function qe(){let t=h.default.join($.default.homedir(),".config","freee-mcp");try{let n=(await g.default.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));await Promise.all(n.map(i=>g.default.unlink(h.default.join(t,i)).catch(()=>{}))),n.length>0&&console.error("\u2705 Cleared legacy company-specific token files")}catch{}}async function B(){let t=await D();if(!t)return null;if(fe(t))return t.access_token;try{return(await be(t.refresh_token)).access_token}catch(e){return console.error("Failed to refresh token:",e),null}}function W(){let t=C.default.randomBytes(32).toString("base64url"),e=C.default.createHash("sha256").update(t).digest("base64url");return{codeVerifier:t,codeChallenge:e}}function M(t,e,n){let i=new URLSearchParams({response_type:"code",client_id:p.freee.clientId,redirect_uri:n,scope:p.oauth.scope,state:e,code_challenge:t,code_challenge_method:"S256"});return`${p.oauth.authorizationEndpoint}?${i.toString()}`}async function G(t,e){let n=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:p.freee.clientId,client_secret:p.freee.clientSecret,code:t,redirect_uri:p.oauth.redirectUri,code_verifier:e})});if(!n.ok){let a=await n.json().catch(()=>({}));throw new Error(`Token exchange failed: ${n.status} ${JSON.stringify(a)}`)}let i=await n.json(),r={access_token:i.access_token,refresh_token:i.refresh_token,expires_at:Date.now()+i.expires_in*1e3,token_type:i.token_type||"Bearer",scope:i.scope||p.oauth.scope};return await E(r),r}var x=null,_=new Map;async function je(t){return new Promise(e=>{let n=Y.default.createServer();n.listen(t,"127.0.0.1",()=>{n.close(()=>{e(!0)})}),n.on("error",()=>{e(!1)})})}async function H(){if(x)return;let t=p.oauth.callbackPort;if(!await je(t))throw new Error(`Port ${t} is already in use. Please close other applications using this port.`);return new Promise((n,i)=>{x=V.default.createServer((r,a)=>{console.error(`\u{1F4E5} Callback request: ${r.method} ${r.url}`);let o=new Z.URL(r.url,`http://127.0.0.1:${t}`);o.pathname==="/callback"?Ie(o,a):o.pathname==="/"?(a.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),a.end("<h1>freee MCP OAuth Server</h1><p>\u30B3\u30FC\u30EB\u30D0\u30C3\u30AF\u30B5\u30FC\u30D0\u30FC\u304C\u7A3C\u50CD\u4E2D\u3067\u3059\u3002</p>")):(a.writeHead(404,{"Content-Type":"text/html; charset=utf-8"}),a.end("<h1>404 Not Found</h1><p>\u3053\u306E\u30D1\u30B9\u306F\u5B58\u5728\u3057\u307E\u305B\u3093\u3002</p>"))}),x.on("error",r=>{console.error("Callback server error:",r),i(r)}),x.listen(t,"127.0.0.1",()=>{console.error(`\u{1F517} OAuth callback server listening on http://127.0.0.1:${t}`),n()})})}function K(t,e){console.error(`\u{1F510} Registering authentication request with state: ${t.substring(0,10)}...`),console.error(`\u{1F510} Code verifier: ${e.substring(0,10)}...`);let n=setTimeout(()=>{_.delete(t),console.error(`\u23F0 Authentication timeout for state: ${t.substring(0,10)}...`)},p.auth.timeoutMs);_.set(t,{codeVerifier:e,resolve:i=>{console.error("\u{1F389} Authentication completed successfully!")},reject:i=>{console.error("\u274C Authentication failed:",i)},timeout:n}),console.error(`\u{1F4DD} Registration complete. Total pending: ${_.size}`)}function L(){if(x){for(let[t,e]of _)clearTimeout(e.timeout),e.reject(new Error("Server shutdown"));_.clear(),x.close(()=>{console.error("\u{1F534} OAuth callback server stopped")}),x=null}}function Ie(t,e){let n=t.searchParams.get("code"),i=t.searchParams.get("state"),r=t.searchParams.get("error"),a=t.searchParams.get("error_description");if(console.error(`\u{1F50D} Callback received - URL: ${t.toString()}`),console.error("\u{1F50D} Callback parameters:",{code:n?`${n.substring(0,10)}...`:null,state:i?`${i.substring(0,10)}...`:null,error:r,errorDescription:a}),console.error(`\u{1F50D} Pending authentications count: ${_.size}`),r){let s=a||r;if(console.error(`\u274C OAuth error: ${r} - ${a}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end(`<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${s}</p>`),i&&_.has(i)){let c=_.get(i);clearTimeout(c.timeout),c.reject(new Error(`OAuth error: ${r} - ${a}`)),_.delete(i)}return}if(!n||!i){console.error("\u274C Missing code or state"),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u30B3\u30FC\u30C9\u307E\u305F\u306F\u72B6\u614B\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002</p>");return}let o=_.get(i);if(!o){console.error(`\u274C Unknown state: ${i}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u4E0D\u660E\u306A\u8A8D\u8A3C\u72B6\u614B\u3067\u3059\u3002\u8A8D\u8A3C\u3092\u518D\u958B\u3057\u3066\u304F\u3060\u3055\u3044\u3002</p>");return}console.error("\u2705 Valid callback received, exchanging code for tokens..."),e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u5B8C\u4E86</h1><p>\u8A8D\u8A3C\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002\u3053\u306E\u30DA\u30FC\u30B8\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002</p>"),clearTimeout(o.timeout),_.delete(i),G(n,o.codeVerifier).then(s=>{console.error("\u{1F389} Token exchange successful!"),o.resolve(s)}).catch(s=>{console.error("\u274C Token exchange failed:",s),o.reject(s)})}var te=y(require("crypto"),1),T=require("zod");var R=y(require("fs/promises"),1),k=y(require("path"),1),Q=y(require("os"),1);function z(){let t=k.default.join(Q.default.homedir(),".config","freee-mcp");return k.default.join(t,"config.json")}async function we(){let t=k.default.dirname(z());await R.default.mkdir(t,{recursive:!0})}async function P(){let t=z();try{let e=await R.default.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=p.freee.companyId||"0",i={defaultCompanyId:n,currentCompanyId:n,companies:{[n]:{id:n,name:"Default Company",description:"Company from environment variable",addedAt:Date.now(),lastUsed:Date.now()}}};return await X(i),i}throw e}}async function X(t){await we();let e=z();await R.default.writeFile(e,JSON.stringify(t,null,2),{mode:384})}async function f(){return(await P()).currentCompanyId}async function ee(t,e,n){let i=await P();i.companies[t]?(e||n)&&(e&&(i.companies[t].name=e),n&&(i.companies[t].description=n)):i.companies[t]={id:t,name:e||`Company ${t}`,description:n||void 0,addedAt:Date.now()},i.companies[t].lastUsed=Date.now(),i.currentCompanyId=t,await X(i)}async function A(){let t=await P();return Object.values(t.companies).sort((e,n)=>(n.lastUsed||0)-(e.lastUsed||0))}async function j(t){return(await P()).companies[t]||null}async function v(t,e,n,i){let r=p.freee.apiUrl,a=await f(),o=await B();if(!o)throw new Error(`\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
1
|
+
"use strict";var _e=Object.create;var J=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty;var xe=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ge(e))!fe.call(t,r)&&r!==n&&J(t,r,{get:()=>e[r],enumerable:!(i=ye(e,r))||i.enumerable});return t};var y=(t,e,n)=>(n=t!=null?_e(he(t)):{},xe(e||!t||!t.__esModule?J(n,"default",{value:t,enumerable:!0}):n,t));var me=require("@modelcontextprotocol/sdk/server/mcp.js"),ce=require("@modelcontextprotocol/sdk/server/stdio.js");var B=parseInt(process.env.FREEE_CALLBACK_PORT||"8080",10),p={freee:{clientId:process.env.FREEE_CLIENT_ID||"",clientSecret:process.env.FREEE_CLIENT_SECRET||"",companyId:process.env.FREEE_COMPANY_ID||"0",apiUrl:"https://api.freee.co.jp"},oauth:{callbackPort:B,redirectUri:`http://127.0.0.1:${B}/callback`,authorizationEndpoint:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenEndpoint:"https://accounts.secure.freee.co.jp/public_api/token",scope:"read write"},server:{name:"freee",version:"1.0.0"},auth:{timeoutMs:5*60*1e3}};var Y=y(require("http"),1),H=require("url"),K=y(require("net"),1);var L=y(require("crypto"),1);var g=y(require("fs/promises"),1),h=y(require("path"),1),$=y(require("os"),1);function C(){let t=h.default.join($.default.homedir(),".config","freee-mcp");return h.default.join(t,"tokens.json")}async function E(t){let e=C(),n=h.default.dirname(e);try{console.error(`\u{1F4C1} Creating directory: ${n}`),await g.default.mkdir(n,{recursive:!0}),console.error(`\u{1F4BE} Writing tokens to: ${e}`),await g.default.writeFile(e,JSON.stringify(t,null,2),{mode:384}),console.error("\u2705 Tokens saved successfully")}catch(i){throw console.error("\u274C Failed to save tokens:",i),i}}async function D(){let t=C();try{let e=await g.default.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=await qe();return n||null}throw console.error("Failed to load tokens:",e),e}}function be(t){return Date.now()<t.expires_at}async function qe(){let t=h.default.join($.default.homedir(),".config","freee-mcp");try{let n=(await g.default.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));if(n.length>0){let i=h.default.join(t,n[0]),r=await g.default.readFile(i,"utf8"),a=JSON.parse(r);return await E(a),await Promise.all(n.map(o=>g.default.unlink(h.default.join(t,o)).catch(()=>{}))),console.error("\u2705 Migrated legacy company-specific tokens to user-based tokens"),a}}catch{}return null}async function je(t){let e=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:p.freee.clientId,client_secret:p.freee.clientSecret})});if(!e.ok){let r=await e.json().catch(()=>({}));throw new Error(`Token refresh failed: ${e.status} ${JSON.stringify(r)}`)}let n=await e.json(),i={access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+n.expires_in*1e3,token_type:n.token_type||"Bearer",scope:n.scope||p.oauth.scope};return await E(i),i}async function W(){let t=C();try{await g.default.unlink(t),console.error("Tokens cleared successfully")}catch(e){if(e.code==="ENOENT"){console.error("No tokens to clear (file does not exist)");return}throw console.error("Failed to clear tokens:",e),e}await Ie()}async function Ie(){let t=h.default.join($.default.homedir(),".config","freee-mcp");try{let n=(await g.default.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));await Promise.all(n.map(i=>g.default.unlink(h.default.join(t,i)).catch(()=>{}))),n.length>0&&console.error("\u2705 Cleared legacy company-specific token files")}catch{}}async function M(){let t=await D();if(!t)return null;if(be(t))return t.access_token;try{return(await je(t.refresh_token)).access_token}catch(e){return console.error("Failed to refresh token:",e),null}}function G(){let t=L.default.randomBytes(32).toString("base64url"),e=L.default.createHash("sha256").update(t).digest("base64url");return{codeVerifier:t,codeChallenge:e}}function V(t,e,n){let i=new URLSearchParams({response_type:"code",client_id:p.freee.clientId,redirect_uri:n,scope:p.oauth.scope,state:e,code_challenge:t,code_challenge_method:"S256"});return`${p.oauth.authorizationEndpoint}?${i.toString()}`}async function Z(t,e,n){let i=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:p.freee.clientId,client_secret:p.freee.clientSecret,code:t,redirect_uri:n,code_verifier:e})});if(!i.ok){let o=await i.json().catch(()=>({}));throw new Error(`Token exchange failed: ${i.status} ${JSON.stringify(o)}`)}let r=await i.json(),a={access_token:r.access_token,refresh_token:r.refresh_token,expires_at:Date.now()+r.expires_in*1e3,token_type:r.token_type||"Bearer",scope:r.scope||p.oauth.scope};return await E(a),a}var x=null,k=null,_=new Map;async function we(t){return new Promise(e=>{let n=K.default.createServer();n.listen(t,"127.0.0.1",()=>{n.close(()=>{e(!0)})}),n.on("error",()=>{e(!1)})})}async function De(t,e=50){for(let n=t;n<t+e;n++)if(await we(n))return n;throw new Error(`No available port found after checking ${e} ports starting from ${t}`)}function z(){if(k===null)throw new Error("Callback server not started. Call startCallbackServer() first.");return`http://127.0.0.1:${k}/callback`}async function Q(){if(x)return;let t=p.oauth.callbackPort,e=await De(t);return k=e,e!==t&&console.error(`\u26A0\uFE0F Port ${t} is in use. Using fallback port ${e} for OAuth callback server.`),new Promise((n,i)=>{x=Y.default.createServer((r,a)=>{console.error(`\u{1F4E5} Callback request: ${r.method} ${r.url}`);let o=new H.URL(r.url,`http://127.0.0.1:${e}`);o.pathname==="/callback"?ve(o,a):o.pathname==="/"?(a.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),a.end("<h1>freee MCP OAuth Server</h1><p>\u30B3\u30FC\u30EB\u30D0\u30C3\u30AF\u30B5\u30FC\u30D0\u30FC\u304C\u7A3C\u50CD\u4E2D\u3067\u3059\u3002</p>")):(a.writeHead(404,{"Content-Type":"text/html; charset=utf-8"}),a.end("<h1>404 Not Found</h1><p>\u3053\u306E\u30D1\u30B9\u306F\u5B58\u5728\u3057\u307E\u305B\u3093\u3002</p>"))}),x.on("error",r=>{console.error("Callback server error:",r),i(r)}),x.listen(e,"127.0.0.1",()=>{console.error(`\u{1F517} OAuth callback server listening on http://127.0.0.1:${e}`),n()})})}function X(t,e){console.error(`\u{1F510} Registering authentication request with state: ${t.substring(0,10)}...`),console.error(`\u{1F510} Code verifier: ${e.substring(0,10)}...`);let n=setTimeout(()=>{_.delete(t),console.error(`\u23F0 Authentication timeout for state: ${t.substring(0,10)}...`)},p.auth.timeoutMs);_.set(t,{codeVerifier:e,resolve:i=>{console.error("\u{1F389} Authentication completed successfully!")},reject:i=>{console.error("\u274C Authentication failed:",i)},timeout:n}),console.error(`\u{1F4DD} Registration complete. Total pending: ${_.size}`)}function N(){if(x){for(let[t,e]of _)clearTimeout(e.timeout),e.reject(new Error("Server shutdown"));_.clear(),x.close(()=>{console.error("\u{1F534} OAuth callback server stopped")}),x=null,k=null}}function ve(t,e){let n=t.searchParams.get("code"),i=t.searchParams.get("state"),r=t.searchParams.get("error"),a=t.searchParams.get("error_description");if(console.error(`\u{1F50D} Callback received - URL: ${t.toString()}`),console.error("\u{1F50D} Callback parameters:",{code:n?`${n.substring(0,10)}...`:null,state:i?`${i.substring(0,10)}...`:null,error:r,errorDescription:a}),console.error(`\u{1F50D} Pending authentications count: ${_.size}`),r){let s=a||r;if(console.error(`\u274C OAuth error: ${r} - ${a}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end(`<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${s}</p>`),i&&_.has(i)){let c=_.get(i);clearTimeout(c.timeout),c.reject(new Error(`OAuth error: ${r} - ${a}`)),_.delete(i)}return}if(!n||!i){console.error("\u274C Missing code or state"),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u30B3\u30FC\u30C9\u307E\u305F\u306F\u72B6\u614B\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002</p>");return}let o=_.get(i);if(!o){console.error(`\u274C Unknown state: ${i}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u4E0D\u660E\u306A\u8A8D\u8A3C\u72B6\u614B\u3067\u3059\u3002\u8A8D\u8A3C\u3092\u518D\u958B\u3057\u3066\u304F\u3060\u3055\u3044\u3002</p>");return}console.error("\u2705 Valid callback received, exchanging code for tokens..."),e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u5B8C\u4E86</h1><p>\u8A8D\u8A3C\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002\u3053\u306E\u30DA\u30FC\u30B8\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002</p>"),clearTimeout(o.timeout),_.delete(i),Z(n,o.codeVerifier,z()).then(s=>{console.error("\u{1F389} Token exchange successful!"),o.resolve(s)}).catch(s=>{console.error("\u274C Token exchange failed:",s),o.reject(s)})}var ie=y(require("crypto"),1),S=require("zod");var P=y(require("fs/promises"),1),R=y(require("path"),1),ee=y(require("os"),1);function F(){let t=R.default.join(ee.default.homedir(),".config","freee-mcp");return R.default.join(t,"config.json")}async function $e(){let t=R.default.dirname(F());await P.default.mkdir(t,{recursive:!0})}async function A(){let t=F();try{let e=await P.default.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=p.freee.companyId||"0",i={defaultCompanyId:n,currentCompanyId:n,companies:{[n]:{id:n,name:"Default Company",description:"Company from environment variable",addedAt:Date.now(),lastUsed:Date.now()}}};return await te(i),i}throw e}}async function te(t){await $e();let e=F();await P.default.writeFile(e,JSON.stringify(t,null,2),{mode:384})}async function f(){return(await A()).currentCompanyId}async function ne(t,e,n){let i=await A();i.companies[t]?(e||n)&&(e&&(i.companies[t].name=e),n&&(i.companies[t].description=n)):i.companies[t]={id:t,name:e||`Company ${t}`,description:n||void 0,addedAt:Date.now()},i.companies[t].lastUsed=Date.now(),i.currentCompanyId=t,await te(i)}async function T(){let t=await A();return Object.values(t.companies).sort((e,n)=>(n.lastUsed||0)-(e.lastUsed||0))}async function j(t){return(await A()).companies[t]||null}async function v(t,e,n,i){let r=p.freee.apiUrl,a=await f(),o=await M();if(!o)throw new Error(`\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
2
2
|
\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${a}
|
|
3
3
|
\u307E\u305F\u306F\u3001FREEE_CLIENT_ID\u74B0\u5883\u5909\u6570\u304C\u6B63\u3057\u304F\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u304B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);let s=new URL(e,r);n&&Object.entries(n).forEach(([m,d])=>{d!==void 0&&s.searchParams.append(m,String(d))}),s.searchParams.append("company_id",String(a));let c=await fetch(s.toString(),{method:t,headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:i?JSON.stringify(typeof i=="string"?JSON.parse(i):i):void 0});if(c.status===401||c.status===403){let m=await c.json().catch(()=>({}));throw new Error(`\u8A8D\u8A3C\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u518D\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
4
4
|
\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${a}
|
|
@@ -18,7 +18,7 @@ ${b.join(`
|
|
|
18
18
|
\u65E2\u5B58\u306E\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u3066\u6B63\u3057\u3044\u69CB\u9020\u3092\u78BA\u8A8D\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059\u3002`,d+=`
|
|
19
19
|
\u4F8B: get_items, get_partners, get_account_items \u306A\u3069\u3067\u65E2\u5B58\u30C7\u30FC\u30BF\u306E\u69CB\u9020\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`))}throw m?.errors||(d+=`
|
|
20
20
|
|
|
21
|
-
\u8A73\u7D30: ${JSON.stringify(m)}`),new Error(d)}return c.json()}function
|
|
21
|
+
\u8A73\u7D30: ${JSON.stringify(m)}`),new Error(d)}return c.json()}function re(t){t.tool("freee_current_user","freee API\u306E\u73FE\u5728\u306E\u30E6\u30FC\u30B6\u30FC\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u8A8D\u8A3C\u72B6\u614B\u3001\u4E8B\u696D\u6240ID\u3001\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30\u304C\u542B\u307E\u308C\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30C6\u30B9\u30C8\u7528\u30FBAPI\u52D5\u4F5C\u78BA\u8A8D\u306B\u6700\u9069\u3011",{},async()=>{try{let e=await f(),n=await j(e);if(!e)return{content:[{type:"text",text:"\u4F1A\u793EID\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002freee_set_company \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u4F1A\u793E\u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"}]};let i=await v("GET","/api/1/users/me");return{content:[{type:"text",text:`\u73FE\u5728\u306E\u30E6\u30FC\u30B6\u30FC\u60C5\u5831:
|
|
22
22
|
\u73FE\u5728\u306E\u4F1A\u793EID: ${e}
|
|
23
23
|
\u4F1A\u793E\u540D: ${n?.name||"Unknown"}
|
|
24
24
|
\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30:
|
|
@@ -33,7 +33,7 @@ ${JSON.stringify(i,null,2)}`}]}}catch(e){return{content:[{type:"text",text:`\u30
|
|
|
33
33
|
OAuth\u8A8D\u8A3C\u3092\u884C\u3046\u306B\u306F\u3001freee developers\u3067\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3057\u3001
|
|
34
34
|
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8ID\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};if(!p.freee.clientSecret)return{content:[{type:"text",text:`FREEE_CLIENT_SECRET\u74B0\u5883\u5909\u6570\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002
|
|
35
35
|
OAuth\u8A8D\u8A3C\u3092\u884C\u3046\u306B\u306F\u3001freee developers\u3067\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3057\u3001
|
|
36
|
-
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let{codeVerifier:e,codeChallenge:n}=
|
|
36
|
+
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let{codeVerifier:e,codeChallenge:n}=G(),i=ie.default.randomBytes(16).toString("hex"),r=V(n,i,z());return X(i,e),console.error(`\u{1F310} Authentication URL: ${r}`),{content:[{type:"text",text:`\u{1F680} OAuth\u8A8D\u8A3C\u3092\u958B\u59CB\u3057\u307E\u3057\u305F\uFF01
|
|
37
37
|
|
|
38
38
|
\u{1F4F1} \u8A8D\u8A3CURL\u3092\u751F\u6210\u3057\u307E\u3057\u305F\u3002\u30D6\u30E9\u30A6\u30B6\u3067\u4EE5\u4E0B\u306EURL\u3092\u958B\u3044\u3066\u8A8D\u8A3C\u3092\u5B8C\u4E86\u3057\u3066\u304F\u3060\u3055\u3044:
|
|
39
39
|
${r}
|
|
@@ -66,21 +66,21 @@ ${r}
|
|
|
66
66
|
|
|
67
67
|
\u{1F527} \u89E3\u6C7A\u624B\u9806:
|
|
68
68
|
1. freee_status - \u5168\u4F53\u7684\u306A\u72B6\u614B\u3092\u78BA\u8A8D
|
|
69
|
-
2. freee_getting_started - \u521D\u671F\u8A2D\u5B9A\u30AC\u30A4\u30C9`}]}}}),t.tool("freee_clear_auth","freee API\u306E\u8A8D\u8A3C\u60C5\u5831\u3092\u30AF\u30EA\u30A2\u3057\u307E\u3059\u3002\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u30C8\u30FC\u30AF\u30F3\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3057\u3001\u6B21\u56DEAPI\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u306B\u306A\u308A\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30A8\u30E9\u30FC\u6642\u306E\u30EA\u30BB\u30C3\u30C8\u7528\u3011",{},async()=>{try{return await
|
|
69
|
+
2. freee_getting_started - \u521D\u671F\u8A2D\u5B9A\u30AC\u30A4\u30C9`}]}}}),t.tool("freee_clear_auth","freee API\u306E\u8A8D\u8A3C\u60C5\u5831\u3092\u30AF\u30EA\u30A2\u3057\u307E\u3059\u3002\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u30C8\u30FC\u30AF\u30F3\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3057\u3001\u6B21\u56DEAPI\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u306B\u306A\u308A\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30A8\u30E9\u30FC\u6642\u306E\u30EA\u30BB\u30C3\u30C8\u7528\u3011",{},async()=>{try{return await W(),{content:[{type:"text",text:`\u8A8D\u8A3C\u60C5\u5831\u304C\u30AF\u30EA\u30A2\u3055\u308C\u307E\u3057\u305F\u3002
|
|
70
70
|
\u6B21\u56DEfreee API\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002
|
|
71
71
|
\u518D\u8A8D\u8A3C\u3059\u308B\u306B\u306F freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u8A8D\u8A3C\u60C5\u5831\u306E\u30AF\u30EA\u30A2\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
72
72
|
|
|
73
73
|
\u{1F527} \u4EE3\u66FF\u624B\u9806:
|
|
74
74
|
1. freee_status - \u72B6\u614B\u3092\u78BA\u8A8D
|
|
75
|
-
2. \u624B\u52D5\u3067\u30D5\u30A1\u30A4\u30EB\u524A\u9664: ~/.config/freee-mcp/tokens.json`}]}}}),t.tool("freee_set_company","\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\u30FB\u5207\u308A\u66FF\u3048\u307E\u3059\u3002\u65B0\u3057\u3044\u4E8B\u696D\u6240\u306E\u5834\u5408\u306F\u81EA\u52D5\u7684\u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",{company_id:
|
|
75
|
+
2. \u624B\u52D5\u3067\u30D5\u30A1\u30A4\u30EB\u524A\u9664: ~/.config/freee-mcp/tokens.json`}]}}}),t.tool("freee_set_company","\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\u30FB\u5207\u308A\u66FF\u3048\u307E\u3059\u3002\u65B0\u3057\u3044\u4E8B\u696D\u6240\u306E\u5834\u5408\u306F\u81EA\u52D5\u7684\u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",{company_id:S.z.string().describe("\u4E8B\u696D\u6240ID\uFF08\u5FC5\u9808\uFF09"),name:S.z.string().optional().describe("\u4E8B\u696D\u6240\u540D\uFF08\u30AA\u30D7\u30B7\u30E7\u30F3\u3001\u65B0\u898F\u8FFD\u52A0\u6642\u306B\u8A2D\u5B9A\uFF09"),description:S.z.string().optional().describe("\u4E8B\u696D\u6240\u306E\u8AAC\u660E\uFF08\u30AA\u30D7\u30B7\u30E7\u30F3\uFF09")},async e=>{try{let{company_id:n,name:i,description:r}=e;await ne(n,i,r);let a=await j(n);return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u3092\u5207\u308A\u66FF\u3048\u307E\u3057\u305F:\\n\u4E8B\u696D\u6240ID: ${n}\\n\u4E8B\u696D\u6240\u540D: ${a?.name||"Unknown"}\\n\u8AAC\u660E: ${a?.description||"\u306A\u3057"}\\n\\n\u{1F680} \u3053\u306E\u4E8B\u696D\u6240\u3067\u3059\u3050\u306BAPI\u3092\u4F7F\u7528\u3067\u304D\u307E\u3059\uFF08\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\uFF09\u3002
|
|
76
76
|
|
|
77
77
|
\u{1F4A1} \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
|
|
78
78
|
\u30FB \u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408: freee_current_user \u3067\u30C6\u30B9\u30C8
|
|
79
|
-
\u30FB \u672A\u8A8D\u8A3C\u306E\u5834\u5408: freee_authenticate \u3067\u8A8D\u8A3C`}]}}catch(n){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n instanceof Error?n.message:String(n)}`}]}}}),t.tool("freee_get_current_company","\u73FE\u5728\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u4E8B\u696D\u6240\u306E\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u3010\u73FE\u5728\u306E\u4F5C\u696D\u5BFE\u8C61\u4E8B\u696D\u6240\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await f(),n=await j(e);return n?{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240\u60C5\u5831:\\n\u4E8B\u696D\u6240ID: ${n.id}\\n\u4E8B\u696D\u6240\u540D: ${n.name}\\n\u8AAC\u660E: ${n.description||"\u306A\u3057"}\\n\u8FFD\u52A0\u65E5\u6642: ${new Date(n.addedAt).toLocaleString()}\\n\u6700\u7D42\u4F7F\u7528: ${n.lastUsed?new Date(n.lastUsed).toLocaleString():"\u306A\u3057"}`}]}:{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${e}\\n\u4E8B\u696D\u6240\u60C5\u5831\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}`}]}}}),t.tool("freee_list_companies","\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u5185\u90E8\u7684\u306Bget_companies\u3092\u547C\u3073\u51FA\u3057\u3066freee API\u304B\u3089\u6700\u65B0\u306E\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u3010\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\u524D\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await v("GET","/api/1/companies"),n=await
|
|
79
|
+
\u30FB \u672A\u8A8D\u8A3C\u306E\u5834\u5408: freee_authenticate \u3067\u8A8D\u8A3C`}]}}catch(n){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n instanceof Error?n.message:String(n)}`}]}}}),t.tool("freee_get_current_company","\u73FE\u5728\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u4E8B\u696D\u6240\u306E\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u3010\u73FE\u5728\u306E\u4F5C\u696D\u5BFE\u8C61\u4E8B\u696D\u6240\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await f(),n=await j(e);return n?{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240\u60C5\u5831:\\n\u4E8B\u696D\u6240ID: ${n.id}\\n\u4E8B\u696D\u6240\u540D: ${n.name}\\n\u8AAC\u660E: ${n.description||"\u306A\u3057"}\\n\u8FFD\u52A0\u65E5\u6642: ${new Date(n.addedAt).toLocaleString()}\\n\u6700\u7D42\u4F7F\u7528: ${n.lastUsed?new Date(n.lastUsed).toLocaleString():"\u306A\u3057"}`}]}:{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${e}\\n\u4E8B\u696D\u6240\u60C5\u5831\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}`}]}}}),t.tool("freee_list_companies","\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u5185\u90E8\u7684\u306Bget_companies\u3092\u547C\u3073\u51FA\u3057\u3066freee API\u304B\u3089\u6700\u65B0\u306E\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u3010\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\u524D\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await v("GET","/api/1/companies"),n=await T(),i=await f();if(!e||!e.companies||e.companies.length===0)return{content:[{type:"text",text:`freee API\u304B\u3089\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u8A8D\u8A3C\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
80
80
|
|
|
81
81
|
\u{1F4A1} \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
|
|
82
82
|
1. freee_auth_status - \u8A8D\u8A3C\u72B6\u614B\u3092\u78BA\u8A8D
|
|
83
|
-
2. freee_authenticate - \u8A8D\u8A3C\u3092\u5B9F\u884C`}]};let r=e.companies.map(a=>{let o=a.id===parseInt(i)?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=n.find(m=>m.id===a.id.toString()),c=s?.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(s.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${a.name} (ID: ${a.id})${o}\\n \u8AAC\u660E: ${a.description||"\u306A\u3057"}\\n ${c}`}).join("\\n\\n");return{content:[{type:"text",text:`freee API\u4E8B\u696D\u6240\u4E00\u89A7 (${e.companies.length}\u4EF6):\\n\\n${r}`}]}}catch(e){try{let n=await
|
|
83
|
+
2. freee_authenticate - \u8A8D\u8A3C\u3092\u5B9F\u884C`}]};let r=e.companies.map(a=>{let o=a.id===parseInt(i)?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=n.find(m=>m.id===a.id.toString()),c=s?.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(s.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${a.name} (ID: ${a.id})${o}\\n \u8AAC\u660E: ${a.description||"\u306A\u3057"}\\n ${c}`}).join("\\n\\n");return{content:[{type:"text",text:`freee API\u4E8B\u696D\u6240\u4E00\u89A7 (${e.companies.length}\u4EF6):\\n\\n${r}`}]}}catch(e){try{let n=await T(),i=await f();if(n.length===0)return{content:[{type:"text",text:`API\u547C\u3073\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
84
84
|
|
|
85
85
|
\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u3082\u3042\u308A\u307E\u305B\u3093\u3002freee_set_company \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u4E8B\u696D\u6240\u3092\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let r=n.map(a=>{let o=a.id===i?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=a.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(a.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${a.name} (ID: ${a.id})${o}\\n \u8AAC\u660E: ${a.description||"\u306A\u3057"}\\n ${s}`}).join("\\n\\n");return{content:[{type:"text",text:`API\u547C\u3073\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
86
86
|
|
|
@@ -203,7 +203,7 @@ freee_set_company [\u4E8B\u696D\u6240ID] # \u5207\u308A\u66FF\u3048
|
|
|
203
203
|
|
|
204
204
|
### \u4E8B\u696D\u6240ID\u304C\u5206\u304B\u3089\u306A\u3044\u5834\u5408
|
|
205
205
|
1. freee\u753B\u9762\u306EURL\u304B\u3089\u78BA\u8A8D\uFF08\u4F8B: /companies/12345/...\uFF09
|
|
206
|
-
2. \u65E2\u5B58\u306E\u8A8D\u8A3C\u304C\u3042\u308C\u3070 \`freee_current_user\` \u3067\u78BA\u8A8D\u53EF\u80FD`}]}}catch(e){return{content:[{type:"text",text:`\u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9\u306E\u8868\u793A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u307E\u305A\u306F\u74B0\u5883\u5909\u6570\u306E\u8A2D\u5B9A\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044\u3002`}]}}}),t.tool("freee_status","\u73FE\u5728\u306Efreee MCP \u30B5\u30FC\u30D0\u30FC\u306E\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3001\u6B21\u306B\u5B9F\u884C\u3059\u3079\u304D\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u63D0\u6848\u3057\u307E\u3059\u3002",{},async()=>{try{let e=await f(),n=await j(e),i=await D(),r=await
|
|
206
|
+
2. \u65E2\u5B58\u306E\u8A8D\u8A3C\u304C\u3042\u308C\u3070 \`freee_current_user\` \u3067\u78BA\u8A8D\u53EF\u80FD`}]}}catch(e){return{content:[{type:"text",text:`\u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9\u306E\u8868\u793A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u307E\u305A\u306F\u74B0\u5883\u5909\u6570\u306E\u8A2D\u5B9A\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044\u3002`}]}}}),t.tool("freee_status","\u73FE\u5728\u306Efreee MCP \u30B5\u30FC\u30D0\u30FC\u306E\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3001\u6B21\u306B\u5B9F\u884C\u3059\u3079\u304D\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u63D0\u6848\u3057\u307E\u3059\u3002",{},async()=>{try{let e=await f(),n=await j(e),i=await D(),r=await T(),a="",o="",s="";if(!e||e==="0"?(a+="\u274C **\u4E8B\u696D\u6240**: \u672A\u8A2D\u5B9A\\n",o+="\u2022 freee_set_company [\u4E8B\u696D\u6240ID] \u3067\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\\n"):n?a+=`\u2705 **\u4E8B\u696D\u6240**: ${n.name} (ID: ${n.id})\\n`:(a+="\u26A0\uFE0F **\u4E8B\u696D\u6240**: \u8A2D\u5B9A\u4E0D\u5B8C\u5168\\n",o+="\u2022 freee_set_company \u3067\u4E8B\u696D\u6240\u60C5\u5831\u3092\u518D\u8A2D\u5B9A\\n"),!i)a+="\u274C **\u8A8D\u8A3C**: \u672A\u8A8D\u8A3C\\n",o+="\u2022 freee_authenticate \u3067\u8A8D\u8A3C\u3092\u5B9F\u884C\\n";else{let c=Date.now()<i.expires_at,m=new Date(i.expires_at).toLocaleString();c?(a+=`\u2705 **\u8A8D\u8A3C**: \u6709\u52B9 (\u671F\u9650: ${m})\\n`,o+="\u2022 freee_current_user \u3067\u30C6\u30B9\u30C8\u5B9F\u884C\\n\u2022 get_deals, get_companies \u306A\u3069\u306EAPI\u30C4\u30FC\u30EB\u304C\u4F7F\u7528\u53EF\u80FD\\n"):(a+=`\u26A0\uFE0F **\u8A8D\u8A3C**: \u671F\u9650\u5207\u308C (${m})\\n`,o+="\u2022 \u6B21\u56DEAPI\u5B9F\u884C\u6642\u306B\u81EA\u52D5\u66F4\u65B0\u3055\u308C\u307E\u3059\\n\u2022 \u624B\u52D5\u66F4\u65B0: freee_authenticate\\n")}return a+=`\u{1F4CA} **\u767B\u9332\u4E8B\u696D\u6240\u6570**: ${r.length}\u4EF6\\n`,r.length>1?o+="\u2022 freee_list_companies \u3067\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u78BA\u8A8D\\n\u2022 freee_set_company [ID] \u3067\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\\n":r.length===1&&(o+="\u2022 freee_set_company [\u65B0\u3057\u3044ID] \u3067\u8FFD\u52A0\u4E8B\u696D\u6240\u3092\u767B\u9332\u53EF\u80FD\\n"),(!p.freee.clientId||!p.freee.clientSecret)&&(s+="\u26A0\uFE0F **\u74B0\u5883\u5909\u6570**: FREEE_CLIENT_ID \u307E\u305F\u306F FREEE_CLIENT_SECRET \u304C\u672A\u8A2D\u5B9A\\n"),e&&n&&i&&Date.now()<i.expires_at&&(o+="\\n\u{1F680} **\u3059\u3050\u306B\u4F7F\u7528\u53EF\u80FD**: freee API\u30C4\u30FC\u30EB\u304C\u5229\u7528\u3067\u304D\u307E\u3059\\n",o+="**\u4F8B**: get_deals, get_companies, get_users, \u306A\u3069"),{content:[{type:"text",text:`# freee MCP \u30B5\u30FC\u30D0\u30FC \u72B6\u614B\u78BA\u8A8D
|
|
207
207
|
|
|
208
208
|
## \u{1F4CA} \u73FE\u5728\u306E\u72B6\u614B
|
|
209
209
|
${a}
|
|
@@ -216,7 +216,7 @@ ${o}
|
|
|
216
216
|
- \`freee_help\` - \u5168\u4F53\u7684\u306A\u4F7F\u3044\u65B9\u30AC\u30A4\u30C9
|
|
217
217
|
- \`freee_getting_started\` - \u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9
|
|
218
218
|
- \`freee_list_companies\` - \u4E8B\u696D\u6240\u4E00\u89A7
|
|
219
|
-
- \`freee_auth_status\` - \u8A8D\u8A3C\u72B6\u614B\u306E\u8A73\u7D30`}]}}catch(e){return{content:[{type:"text",text:`\u72B6\u614B\u78BA\u8A8D\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u57FA\u672C\u7684\u306A\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044:\\n1. freee_getting_started\\n2. freee_set_company [\u4E8B\u696D\u6240ID]\\n3. freee_authenticate`}]}}})}var
|
|
219
|
+
- \`freee_auth_status\` - \u8A8D\u8A3C\u72B6\u614B\u306E\u8A73\u7D30`}]}}catch(e){return{content:[{type:"text",text:`\u72B6\u614B\u78BA\u8A8D\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u57FA\u672C\u7684\u306A\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044:\\n1. freee_getting_started\\n2. freee_set_company [\u4E8B\u696D\u6240ID]\\n3. freee_authenticate`}]}}})}var pe=require("zod");var ae={openapi:"3.0.1",info:{title:"freee\u4F1A\u8A08 API",description:`
|
|
220
220
|
<hr />
|
|
221
221
|
<h2 id="start_guide">\u30B9\u30BF\u30FC\u30C8\u30AC\u30A4\u30C9</h2>
|
|
222
222
|
|
|
@@ -4985,4 +4985,4 @@ submitted \u306F\u8ACB\u6C42\u66F8\u627F\u8A8D\u30EF\u30FC\u30AF\u30D5\u30ED\u30
|
|
|
4985
4985
|
<ul>
|
|
4986
4986
|
<li>normal\u3001discount\u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u3001account_item_id,tax_code\u3068unit_price\u304C\u5FC5\u9808\u3068\u306A\u308A\u307E\u3059\u3002</li>
|
|
4987
4987
|
<li>normal\u3092\u6307\u5B9A\u3057\u305F\u5834\u5408\u3001qty\u304C\u5FC5\u9808\u3068\u306A\u308A\u307E\u3059\u3002</li>
|
|
4988
|
-
</ul>`,example:"normal",enum:["normal","discount","text"]},qty:{type:"number",minimum:0,maximum:99999999,description:"\u6570\u91CF",example:1},unit:{type:"string",description:"\u5358\u4F4D",example:"\u500B"},unit_price:{type:"number",minimum:-999999999999,maximum:999999999999,description:"\u5358\u4FA1 (tax_entry_method: inclusive\u306E\u5834\u5408\u306F\u7A0E\u8FBC\u4FA1\u683C\u3001tax_entry_method: exclusive\u306E\u5834\u5408\u306F\u7A0E\u629C\u4FA1\u683C\u3068\u306A\u308A\u307E\u3059)",example:1},vat:{type:"integer",format:"int64",nullable:!0,description:"\u6D88\u8CBB\u7A0E\u984D",example:8e3},description:{type:"string",description:"\u5099\u8003",example:"\u5099\u8003"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},tax_code:{type:"integer",format:"int64",minimum:0,maximum:2147483647,description:"\u7A0E\u533A\u5206\u30B3\u30FC\u30C9",example:1},item_id:{type:"integer",format:"int64",minimum:1,description:"\u54C1\u76EEID",example:1},section_id:{type:"integer",format:"int64",minimum:1,description:"\u90E8\u9580ID",example:1},tag_ids:{type:"array",items:{type:"integer",format:"int64",minimum:1,description:"\u30E1\u30E2\u30BF\u30B0ID",example:1}},segment_1_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF11\u30BF\u30B0ID",example:1},segment_2_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF12\u30BF\u30B0ID",example:1},segment_3_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF13\u30BF\u30B0ID",example:1}}}}}},fixedAssetResponse:{type:"object",required:["fixed_assets","fiscal_year","up_to_date","up_to_date_reasons"],properties:{fixed_assets:{type:"array",items:{type:"object",properties:{company_id:{type:"integer",format:"int64",minimum:1,description:"\u4E8B\u696D\u6240ID",example:1},id:{type:"integer",format:"int64",minimum:1,description:"\u56FA\u5B9A\u8CC7\u7523ID",example:1},name:{type:"string",description:"\u56FA\u5B9A\u8CC7\u7523\u540D",example:"pc"},management_number:{type:"string",nullable:!0,description:"\u7BA1\u7406\u756A\u53F7",example:"pc-0001"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:22},section_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u90E8\u9580ID",example:0},item_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u54C1\u76EEID",example:0},depreciation_method:{type:"string",description:"\u511F\u5374\u65B9\u6CD5:(\u5C11\u984D\u511F\u5374: small_sum_method, \u4E00\u62EC\u511F\u5374: lump_sum_method, \u5B9A\u984D\u6CD5: straight_line_method, \u5B9A\u7387\u6CD5: multiple_method, \u65E7\u5B9A\u7387\u6CD5: old_multiple_method, \u65E7\u5B9A\u984D\u6CD5: old_straight_line_method, \u511F\u5374\u306A\u3057: non_depreciate_method, \u4EFB\u610F\u511F\u5374: voluntary_method, \u5373\u6642\u511F\u5374: immediate_method, \u5747\u7B49\u511F\u5374: equal_method)",enum:["small_sum_method","lump_sum_method","straight_line_method","multiple_method","old_multiple_method","old_straight_line_method","non_depreciate_method","voluntary_method","immediate_method","equal_method"],example:"straight_line_method"},depreciation_account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u6E1B\u4FA1\u511F\u5374\u306B\u4F7F\u3046\u52D8\u5B9A\u79D1\u76EEID",example:99},prefecture_code:{type:"integer",format:"int64",minimum:-1,maximum:46,description:"\u90FD\u9053\u5E9C\u770C\u30B3\u30FC\u30C9\uFF08-1: \u8A2D\u5B9A\u3057\u306A\u3044\u30010:\u5317\u6D77\u9053\u30011:\u9752\u68EE\u30012:\u5CA9\u624B\u30013:\u5BAE\u57CE\u30014:\u79CB\u7530\u30015:\u5C71\u5F62\u30016:\u798F\u5CF6\u30017:\u8328\u57CE\u30018:\u6803\u6728\u30019:\u7FA4\u99AC\u300110:\u57FC\u7389\u300111:\u5343\u8449\u300112:\u6771\u4EAC\u300113:\u795E\u5948\u5DDD\u300114:\u65B0\u6F5F\u300115:\u5BCC\u5C71\u300116:\u77F3\u5DDD\u300117:\u798F\u4E95\u300118:\u5C71\u68A8\u300119:\u9577\u91CE\u300120:\u5C90\u961C\u300121:\u9759\u5CA1\u300122:\u611B\u77E5\u300123:\u4E09\u91CD\u300124:\u6ECB\u8CC0\u300125:\u4EAC\u90FD\u300126:\u5927\u962A\u300127:\u5175\u5EAB\u300128:\u5948\u826F\u300129:\u548C\u6B4C\u5C71\u300130:\u9CE5\u53D6\u300131:\u5CF6\u6839\u300132:\u5CA1\u5C71\u300133:\u5E83\u5CF6\u300134:\u5C71\u53E3\u300135:\u5FB3\u5CF6\u300136:\u9999\u5DDD\u300137:\u611B\u5A9B\u300138:\u9AD8\u77E5\u300139:\u798F\u5CA1\u300140:\u4F50\u8CC0\u300141:\u9577\u5D0E\u300142:\u718A\u672C\u300143:\u5927\u5206\u300144:\u5BAE\u5D0E\u300145:\u9E7F\u5150\u5CF6\u300146:\u6C96\u7E04",example:4,nullable:!0},city_name:{type:"string",nullable:!0,description:"\u7533\u544A\u5148\u5E02\u533A\u753A\u6751",example:"\u6E2F\u533A"},depreciation_amount:{type:"integer",format:"int64",description:"\u672C\u5E74\u5206\u306E\u511F\u5374\u8CBB\u5408\u8A08",example:"18533"},acquisition_cost:{type:"integer",format:"int64",description:"\u53D6\u5F97\u4FA1\u984D",example:"150000"},opening_balance:{type:"integer",format:"int64",description:"\u671F\u9996\u6B8B\u9AD8\uFF08\u53D6\u5F97\u65E5\u304C\u4F1A\u8A08\u671F\u9593\u306B\u542B\u307E\u308C\u308B\u3068\u304D\u671F\u9996\u6B8B\u9AD8\u306F0\u306B\u306A\u308A\u307E\u3059\u3002\uFF09",example:"92000"},undepreciated_balance:{type:"integer",format:"int64",description:"\u672A\u511F\u5374\u6B8B\u9AD8",example:"46000"},opening_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u9996\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"100000"},closing_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u672B\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"46000"},life_years:{type:"integer",format:"int64",description:"\u8010\u7528\u5E74\u6570",example:"5"},acquisition_date:{type:"string",description:"\u53D6\u5F97\u65E5",format:"date",example:"2021-07-13"},created_at:{type:"string",description:"\u4F5C\u6210\u65E5\u6642\uFF08ISO8601\u5F62\u5F0F\uFF09",example:"2021-07-15T18:30:24+09:00"},depreciation_status:{type:"string",description:"\u58F2\u5374\u3082\u3057\u304F\u306F\u9664\u5374\u30B9\u30C6\u30FC\u30BF\u30B9: (\u58F2\u5374\u6E08: sold, \u9664\u5374\u6E08: retired, \u511F\u5374\u6E08: depreciated, \u511F\u5374\u4E2D: depreciation, \u511F\u5374\u306A\u3057: non_depreciation)",enum:["sold","retired","depreciated","depreciation","non_depreciation"],example:"depreciation"},retire_date:{type:"string",format:"date",nullable:!0,description:"\u9664\u5374\u65E5\u3001\u3082\u3057\u304F\u306F\u58F2\u5374\u65E5",example:"2022-03-24"}}}},fiscal_year:{type:"object",required:["start_date","end_date"],properties:{start_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u958B\u59CB\u65E5 (yyyy-mm-dd)",example:"2022-01-01"},end_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u7D42\u4E86\u65E5 (yyyy-mm-dd)",example:"2022-12-31"}}},up_to_date:{type:"boolean",description:"\u96C6\u8A08\u7D50\u679C\u304C\u6700\u65B0\u304B\u3069\u3046\u304B",example:!0},up_to_date_reasons:{type:"array",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u5834\u5408\u306E\u8981\u56E0\u60C5\u5831",items:{type:"object",required:["code","message"],properties:{code:{type:"string",description:"\u30B3\u30FC\u30C9",example:"depreciation_creating",enum:["depreciation_creating","depreciation_create_error"]},message:{type:"string",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u7406\u7531",example:"\u5F53\u671F\u306E\u56FA\u5B9A\u8CC7\u7523\u306E\u511F\u5374\u4F5C\u6210\u304C\u5B8C\u4E86\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6B63\u3057\u3044\u96C6\u8A08\u7D50\u679C\u3067\u306A\u3044\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002"}}}}}},generalLedgersResponse:{type:"object",required:["general_ledgers"],properties:{general_ledgers:{type:"array",items:{type:"object",properties:{account_item_id:{type:"integer",format:"int64",description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},account_item_name:{type:"string",description:"\u52D8\u5B9A\u79D1\u76EE\u540D",example:"\u58F2\u639B\u91D1"},total_amount:{type:"integer",format:"int64",description:"\u767A\u751F\u984D\u7D2F\u8A08",example:100},final_balance:{type:"integer",format:"int64",description:"\u6B8B\u9AD8",example:100},debit_amount:{type:"integer",format:"int64",description:"\u501F\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100},credit_amount:{type:"integer",format:"int64",description:"\u8CB8\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100}}}}}},accountGroupCreateParams:{type:"object",required:["company_id","name","account_category_id"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",format:"int64",example:1},name:{type:"string",maxLength:20,description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D (20\u6587\u5B57\u4EE5\u5185)",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EA\u30FCID Selectables\u30D5\u30A9\u30FC\u30E0\u7528\u9078\u629E\u9805\u76EE\u60C5\u5831\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8(account_groups.account_category_id)\u3067\u53D6\u5F97\u53EF\u80FD\u3067\u3059",format:"int64",example:1},index:{type:"integer",description:"\u8868\u793A\u9806",format:"int64",example:1}}},accountGroupCreateResponse:{type:"object",required:["account_group"],properties:{account_group:{type:"object",required:["company_id","id","name","account_structure_id","account_category_id","index"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",example:1,format:"int64"},id:{type:"integer",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D(\u5C0F\u30AB\u30C6\u30B4\u30EA\u30FC)ID",example:1,format:"int64"},name:{type:"string",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_structure_id:{type:"integer",description:"\u5E74\u5EA6ID",example:1,format:"int64"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EAID",example:1,format:"int64"},index:{type:"integer",description:"\u8868\u793A\u9806",example:1,format:"int64"}}}}}},securitySchemes:{oauth2:{type:"oauth2",flows:{authorizationCode:{authorizationUrl:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenUrl:"https://accounts.secure.freee.co.jp/public_api/token",scopes:{write:"\u30C7\u30FC\u30BF\u306E\u66F8\u304D\u8FBC\u307F",read:"\u30C7\u30FC\u30BF\u306E\u8AAD\u307F\u53D6\u308A"}}}}}}};var I=require("zod");function N(t){let{type:e}=t.schema||t,{description:n,required:i}=t,r;switch(e){case"string":r=I.z.string();break;case"integer":r=I.z.number().int();break;case"number":r=I.z.number();break;case"boolean":r=I.z.boolean();break;default:r=I.z.any()}return n&&(r=r.describe(n)),i||(r=r.optional()),r}function re(t){let e=t.replace(/^\/api\/\d+\//,"").replace(/\/{[^}]+}/g,"_by_id").replace(/\//g,"_");return e.length>50&&(e=e.substring(0,50)),e}function oe(t){let e=ie.paths;Object.keys(e).sort().forEach(i=>{let r=e[i];Object.entries(r).forEach(([a,o])=>{let s=`${a}_${re(i)}`,c=o.summary||o.description||"",m={},d=o.parameters?.filter(l=>l.in==="path")||[];d.forEach(l=>{m[l.name]=N(l)});let b=o.parameters?.filter(l=>l.in==="query")||[];b.forEach(l=>{let u=N(l);l.name==="company_id"&&(u=u.optional()),m[l.name]=u});let w=ae.z.any();(a==="post"||a==="put")&&o.requestBody?.content?.["application/json"]?.schema&&(m.body=w.describe("Request body")),t.tool(s,c,m,async l=>{try{let u=i;d.forEach(q=>{u=u.replace(`{${q.name}}`,String(l[q.name]))});let F={};b.forEach(q=>{l[q.name]!==void 0&&(F[q.name]=l[q.name])});let ce=a==="post"||a==="put"?l.body:void 0,le=await v(a.toUpperCase(),u,F,ce);return{content:[{type:"text",text:JSON.stringify(le,null,2)}]}}catch(u){return{content:[{type:"text",text:`Error: ${u instanceof Error?u.message:String(u)}`}]}}})})})}async function me(){let t=new pe.McpServer({name:p.server.name,version:p.server.version});ne(t),oe(t);try{await H(),console.error(`\u2705 OAuth callback server started on http://127.0.0.1:${p.oauth.callbackPort}`)}catch(n){console.error("\u26A0\uFE0F Failed to start callback server:",n),console.error("OAuth authentication will fall back to manual mode")}let e=new se.StdioServerTransport;await t.connect(e),console.error("Freee MCP Server running on stdio"),process.on("SIGINT",()=>{L(),process.exit(0)}),process.on("SIGTERM",()=>{L(),process.exit(0)})}var ve=async()=>{await me()};ve().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|
|
4988
|
+
</ul>`,example:"normal",enum:["normal","discount","text"]},qty:{type:"number",minimum:0,maximum:99999999,description:"\u6570\u91CF",example:1},unit:{type:"string",description:"\u5358\u4F4D",example:"\u500B"},unit_price:{type:"number",minimum:-999999999999,maximum:999999999999,description:"\u5358\u4FA1 (tax_entry_method: inclusive\u306E\u5834\u5408\u306F\u7A0E\u8FBC\u4FA1\u683C\u3001tax_entry_method: exclusive\u306E\u5834\u5408\u306F\u7A0E\u629C\u4FA1\u683C\u3068\u306A\u308A\u307E\u3059)",example:1},vat:{type:"integer",format:"int64",nullable:!0,description:"\u6D88\u8CBB\u7A0E\u984D",example:8e3},description:{type:"string",description:"\u5099\u8003",example:"\u5099\u8003"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},tax_code:{type:"integer",format:"int64",minimum:0,maximum:2147483647,description:"\u7A0E\u533A\u5206\u30B3\u30FC\u30C9",example:1},item_id:{type:"integer",format:"int64",minimum:1,description:"\u54C1\u76EEID",example:1},section_id:{type:"integer",format:"int64",minimum:1,description:"\u90E8\u9580ID",example:1},tag_ids:{type:"array",items:{type:"integer",format:"int64",minimum:1,description:"\u30E1\u30E2\u30BF\u30B0ID",example:1}},segment_1_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF11\u30BF\u30B0ID",example:1},segment_2_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF12\u30BF\u30B0ID",example:1},segment_3_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF13\u30BF\u30B0ID",example:1}}}}}},fixedAssetResponse:{type:"object",required:["fixed_assets","fiscal_year","up_to_date","up_to_date_reasons"],properties:{fixed_assets:{type:"array",items:{type:"object",properties:{company_id:{type:"integer",format:"int64",minimum:1,description:"\u4E8B\u696D\u6240ID",example:1},id:{type:"integer",format:"int64",minimum:1,description:"\u56FA\u5B9A\u8CC7\u7523ID",example:1},name:{type:"string",description:"\u56FA\u5B9A\u8CC7\u7523\u540D",example:"pc"},management_number:{type:"string",nullable:!0,description:"\u7BA1\u7406\u756A\u53F7",example:"pc-0001"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:22},section_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u90E8\u9580ID",example:0},item_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u54C1\u76EEID",example:0},depreciation_method:{type:"string",description:"\u511F\u5374\u65B9\u6CD5:(\u5C11\u984D\u511F\u5374: small_sum_method, \u4E00\u62EC\u511F\u5374: lump_sum_method, \u5B9A\u984D\u6CD5: straight_line_method, \u5B9A\u7387\u6CD5: multiple_method, \u65E7\u5B9A\u7387\u6CD5: old_multiple_method, \u65E7\u5B9A\u984D\u6CD5: old_straight_line_method, \u511F\u5374\u306A\u3057: non_depreciate_method, \u4EFB\u610F\u511F\u5374: voluntary_method, \u5373\u6642\u511F\u5374: immediate_method, \u5747\u7B49\u511F\u5374: equal_method)",enum:["small_sum_method","lump_sum_method","straight_line_method","multiple_method","old_multiple_method","old_straight_line_method","non_depreciate_method","voluntary_method","immediate_method","equal_method"],example:"straight_line_method"},depreciation_account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u6E1B\u4FA1\u511F\u5374\u306B\u4F7F\u3046\u52D8\u5B9A\u79D1\u76EEID",example:99},prefecture_code:{type:"integer",format:"int64",minimum:-1,maximum:46,description:"\u90FD\u9053\u5E9C\u770C\u30B3\u30FC\u30C9\uFF08-1: \u8A2D\u5B9A\u3057\u306A\u3044\u30010:\u5317\u6D77\u9053\u30011:\u9752\u68EE\u30012:\u5CA9\u624B\u30013:\u5BAE\u57CE\u30014:\u79CB\u7530\u30015:\u5C71\u5F62\u30016:\u798F\u5CF6\u30017:\u8328\u57CE\u30018:\u6803\u6728\u30019:\u7FA4\u99AC\u300110:\u57FC\u7389\u300111:\u5343\u8449\u300112:\u6771\u4EAC\u300113:\u795E\u5948\u5DDD\u300114:\u65B0\u6F5F\u300115:\u5BCC\u5C71\u300116:\u77F3\u5DDD\u300117:\u798F\u4E95\u300118:\u5C71\u68A8\u300119:\u9577\u91CE\u300120:\u5C90\u961C\u300121:\u9759\u5CA1\u300122:\u611B\u77E5\u300123:\u4E09\u91CD\u300124:\u6ECB\u8CC0\u300125:\u4EAC\u90FD\u300126:\u5927\u962A\u300127:\u5175\u5EAB\u300128:\u5948\u826F\u300129:\u548C\u6B4C\u5C71\u300130:\u9CE5\u53D6\u300131:\u5CF6\u6839\u300132:\u5CA1\u5C71\u300133:\u5E83\u5CF6\u300134:\u5C71\u53E3\u300135:\u5FB3\u5CF6\u300136:\u9999\u5DDD\u300137:\u611B\u5A9B\u300138:\u9AD8\u77E5\u300139:\u798F\u5CA1\u300140:\u4F50\u8CC0\u300141:\u9577\u5D0E\u300142:\u718A\u672C\u300143:\u5927\u5206\u300144:\u5BAE\u5D0E\u300145:\u9E7F\u5150\u5CF6\u300146:\u6C96\u7E04",example:4,nullable:!0},city_name:{type:"string",nullable:!0,description:"\u7533\u544A\u5148\u5E02\u533A\u753A\u6751",example:"\u6E2F\u533A"},depreciation_amount:{type:"integer",format:"int64",description:"\u672C\u5E74\u5206\u306E\u511F\u5374\u8CBB\u5408\u8A08",example:"18533"},acquisition_cost:{type:"integer",format:"int64",description:"\u53D6\u5F97\u4FA1\u984D",example:"150000"},opening_balance:{type:"integer",format:"int64",description:"\u671F\u9996\u6B8B\u9AD8\uFF08\u53D6\u5F97\u65E5\u304C\u4F1A\u8A08\u671F\u9593\u306B\u542B\u307E\u308C\u308B\u3068\u304D\u671F\u9996\u6B8B\u9AD8\u306F0\u306B\u306A\u308A\u307E\u3059\u3002\uFF09",example:"92000"},undepreciated_balance:{type:"integer",format:"int64",description:"\u672A\u511F\u5374\u6B8B\u9AD8",example:"46000"},opening_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u9996\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"100000"},closing_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u672B\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"46000"},life_years:{type:"integer",format:"int64",description:"\u8010\u7528\u5E74\u6570",example:"5"},acquisition_date:{type:"string",description:"\u53D6\u5F97\u65E5",format:"date",example:"2021-07-13"},created_at:{type:"string",description:"\u4F5C\u6210\u65E5\u6642\uFF08ISO8601\u5F62\u5F0F\uFF09",example:"2021-07-15T18:30:24+09:00"},depreciation_status:{type:"string",description:"\u58F2\u5374\u3082\u3057\u304F\u306F\u9664\u5374\u30B9\u30C6\u30FC\u30BF\u30B9: (\u58F2\u5374\u6E08: sold, \u9664\u5374\u6E08: retired, \u511F\u5374\u6E08: depreciated, \u511F\u5374\u4E2D: depreciation, \u511F\u5374\u306A\u3057: non_depreciation)",enum:["sold","retired","depreciated","depreciation","non_depreciation"],example:"depreciation"},retire_date:{type:"string",format:"date",nullable:!0,description:"\u9664\u5374\u65E5\u3001\u3082\u3057\u304F\u306F\u58F2\u5374\u65E5",example:"2022-03-24"}}}},fiscal_year:{type:"object",required:["start_date","end_date"],properties:{start_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u958B\u59CB\u65E5 (yyyy-mm-dd)",example:"2022-01-01"},end_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u7D42\u4E86\u65E5 (yyyy-mm-dd)",example:"2022-12-31"}}},up_to_date:{type:"boolean",description:"\u96C6\u8A08\u7D50\u679C\u304C\u6700\u65B0\u304B\u3069\u3046\u304B",example:!0},up_to_date_reasons:{type:"array",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u5834\u5408\u306E\u8981\u56E0\u60C5\u5831",items:{type:"object",required:["code","message"],properties:{code:{type:"string",description:"\u30B3\u30FC\u30C9",example:"depreciation_creating",enum:["depreciation_creating","depreciation_create_error"]},message:{type:"string",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u7406\u7531",example:"\u5F53\u671F\u306E\u56FA\u5B9A\u8CC7\u7523\u306E\u511F\u5374\u4F5C\u6210\u304C\u5B8C\u4E86\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6B63\u3057\u3044\u96C6\u8A08\u7D50\u679C\u3067\u306A\u3044\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002"}}}}}},generalLedgersResponse:{type:"object",required:["general_ledgers"],properties:{general_ledgers:{type:"array",items:{type:"object",properties:{account_item_id:{type:"integer",format:"int64",description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},account_item_name:{type:"string",description:"\u52D8\u5B9A\u79D1\u76EE\u540D",example:"\u58F2\u639B\u91D1"},total_amount:{type:"integer",format:"int64",description:"\u767A\u751F\u984D\u7D2F\u8A08",example:100},final_balance:{type:"integer",format:"int64",description:"\u6B8B\u9AD8",example:100},debit_amount:{type:"integer",format:"int64",description:"\u501F\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100},credit_amount:{type:"integer",format:"int64",description:"\u8CB8\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100}}}}}},accountGroupCreateParams:{type:"object",required:["company_id","name","account_category_id"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",format:"int64",example:1},name:{type:"string",maxLength:20,description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D (20\u6587\u5B57\u4EE5\u5185)",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EA\u30FCID Selectables\u30D5\u30A9\u30FC\u30E0\u7528\u9078\u629E\u9805\u76EE\u60C5\u5831\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8(account_groups.account_category_id)\u3067\u53D6\u5F97\u53EF\u80FD\u3067\u3059",format:"int64",example:1},index:{type:"integer",description:"\u8868\u793A\u9806",format:"int64",example:1}}},accountGroupCreateResponse:{type:"object",required:["account_group"],properties:{account_group:{type:"object",required:["company_id","id","name","account_structure_id","account_category_id","index"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",example:1,format:"int64"},id:{type:"integer",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D(\u5C0F\u30AB\u30C6\u30B4\u30EA\u30FC)ID",example:1,format:"int64"},name:{type:"string",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_structure_id:{type:"integer",description:"\u5E74\u5EA6ID",example:1,format:"int64"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EAID",example:1,format:"int64"},index:{type:"integer",description:"\u8868\u793A\u9806",example:1,format:"int64"}}}}}},securitySchemes:{oauth2:{type:"oauth2",flows:{authorizationCode:{authorizationUrl:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenUrl:"https://accounts.secure.freee.co.jp/public_api/token",scopes:{write:"\u30C7\u30FC\u30BF\u306E\u66F8\u304D\u8FBC\u307F",read:"\u30C7\u30FC\u30BF\u306E\u8AAD\u307F\u53D6\u308A"}}}}}}};var I=require("zod");function U(t){let{type:e}=t.schema||t,{description:n,required:i}=t,r;switch(e){case"string":r=I.z.string();break;case"integer":r=I.z.number().int();break;case"number":r=I.z.number();break;case"boolean":r=I.z.boolean();break;default:r=I.z.any()}return n&&(r=r.describe(n)),i||(r=r.optional()),r}function oe(t){let e=t.replace(/^\/api\/\d+\//,"").replace(/\/{[^}]+}/g,"_by_id").replace(/\//g,"_");return e.length>50&&(e=e.substring(0,50)),e}function se(t){let e=ae.paths;Object.keys(e).sort().forEach(i=>{let r=e[i];Object.entries(r).forEach(([a,o])=>{let s=`${a}_${oe(i)}`,c=o.summary||o.description||"",m={},d=o.parameters?.filter(l=>l.in==="path")||[];d.forEach(l=>{m[l.name]=U(l)});let b=o.parameters?.filter(l=>l.in==="query")||[];b.forEach(l=>{let u=U(l);l.name==="company_id"&&(u=u.optional()),m[l.name]=u});let w=pe.z.any();(a==="post"||a==="put")&&o.requestBody?.content?.["application/json"]?.schema&&(m.body=w.describe("Request body")),t.tool(s,c,m,async l=>{try{let u=i;d.forEach(q=>{u=u.replace(`{${q.name}}`,String(l[q.name]))});let O={};b.forEach(q=>{l[q.name]!==void 0&&(O[q.name]=l[q.name])});let de=a==="post"||a==="put"?l.body:void 0,ue=await v(a.toUpperCase(),u,O,de);return{content:[{type:"text",text:JSON.stringify(ue,null,2)}]}}catch(u){return{content:[{type:"text",text:`Error: ${u instanceof Error?u.message:String(u)}`}]}}})})})}async function le(){let t=new me.McpServer({name:p.server.name,version:p.server.version});re(t),se(t);try{await Q(),console.error(`\u2705 OAuth callback server started on http://127.0.0.1:${p.oauth.callbackPort}`)}catch(n){console.error("\u26A0\uFE0F Failed to start callback server:",n),console.error("OAuth authentication will fall back to manual mode")}let e=new ce.StdioServerTransport;await t.connect(e),console.error("Freee MCP Server running on stdio"),process.on("SIGINT",()=>{N(),process.exit(0)}),process.on("SIGTERM",()=>{N(),process.exit(0)})}var ke=async()=>{await le()};ke().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{McpServer as ge}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as he}from"@modelcontextprotocol/sdk/server/stdio.js";var N=parseInt(process.env.FREEE_CALLBACK_PORT||"8080",10),p={freee:{clientId:process.env.FREEE_CLIENT_ID||"",clientSecret:process.env.FREEE_CLIENT_SECRET||"",companyId:process.env.FREEE_COMPANY_ID||"0",apiUrl:"https://api.freee.co.jp"},oauth:{callbackPort:N,redirectUri:`http://127.0.0.1:${N}/callback`,authorizationEndpoint:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenEndpoint:"https://accounts.secure.freee.co.jp/public_api/token",scope:"read write"},server:{name:"freee",version:"1.0.0"},auth:{timeoutMs:5*60*1e3}};import oe from"http";import{URL as pe}from"url";import se from"net";import O from"crypto";import y from"fs/promises";import h from"path";import k from"os";function R(){let t=h.join(k.homedir(),".config","freee-mcp");return h.join(t,"tokens.json")}async function v(t){let e=R(),n=h.dirname(e);try{console.error(`\u{1F4C1} Creating directory: ${n}`),await y.mkdir(n,{recursive:!0}),console.error(`\u{1F4BE} Writing tokens to: ${e}`),await y.writeFile(e,JSON.stringify(t,null,2),{mode:384}),console.error("\u2705 Tokens saved successfully")}catch(i){throw console.error("\u274C Failed to save tokens:",i),i}}async function I(){let t=R();try{let e=await y.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=await ie();return n||null}throw console.error("Failed to load tokens:",e),e}}function ne(t){return Date.now()<t.expires_at}async function ie(){let t=h.join(k.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));if(n.length>0){let i=h.join(t,n[0]),a=await y.readFile(i,"utf8"),r=JSON.parse(a);return await v(r),await Promise.all(n.map(o=>y.unlink(h.join(t,o)).catch(()=>{}))),console.error("\u2705 Migrated legacy company-specific tokens to user-based tokens"),r}}catch{}return null}async function re(t){let e=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:p.freee.clientId,client_secret:p.freee.clientSecret})});if(!e.ok){let a=await e.json().catch(()=>({}));throw new Error(`Token refresh failed: ${e.status} ${JSON.stringify(a)}`)}let n=await e.json(),i={access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+n.expires_in*1e3,token_type:n.token_type||"Bearer",scope:n.scope||p.oauth.scope};return await v(i),i}async function F(){let t=R();try{await y.unlink(t),console.error("Tokens cleared successfully")}catch(e){if(e.code==="ENOENT"){console.error("No tokens to clear (file does not exist)");return}throw console.error("Failed to clear tokens:",e),e}await ae()}async function ae(){let t=h.join(k.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));await Promise.all(n.map(i=>y.unlink(h.join(t,i)).catch(()=>{}))),n.length>0&&console.error("\u2705 Cleared legacy company-specific token files")}catch{}}async function U(){let t=await I();if(!t)return null;if(ne(t))return t.access_token;try{return(await re(t.refresh_token)).access_token}catch(e){return console.error("Failed to refresh token:",e),null}}function J(){let t=O.randomBytes(32).toString("base64url"),e=O.createHash("sha256").update(t).digest("base64url");return{codeVerifier:t,codeChallenge:e}}function B(t,e,n){let i=new URLSearchParams({response_type:"code",client_id:p.freee.clientId,redirect_uri:n,scope:p.oauth.scope,state:e,code_challenge:t,code_challenge_method:"S256"});return`${p.oauth.authorizationEndpoint}?${i.toString()}`}async function W(t,e){let n=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:p.freee.clientId,client_secret:p.freee.clientSecret,code:t,redirect_uri:p.oauth.redirectUri,code_verifier:e})});if(!n.ok){let r=await n.json().catch(()=>({}));throw new Error(`Token exchange failed: ${n.status} ${JSON.stringify(r)}`)}let i=await n.json(),a={access_token:i.access_token,refresh_token:i.refresh_token,expires_at:Date.now()+i.expires_in*1e3,token_type:i.token_type||"Bearer",scope:i.scope||p.oauth.scope};return await v(a),a}var f=null,_=new Map;async function me(t){return new Promise(e=>{let n=se.createServer();n.listen(t,"127.0.0.1",()=>{n.close(()=>{e(!0)})}),n.on("error",()=>{e(!1)})})}async function M(){if(f)return;let t=p.oauth.callbackPort;if(!await me(t))throw new Error(`Port ${t} is already in use. Please close other applications using this port.`);return new Promise((n,i)=>{f=oe.createServer((a,r)=>{console.error(`\u{1F4E5} Callback request: ${a.method} ${a.url}`);let o=new pe(a.url,`http://127.0.0.1:${t}`);o.pathname==="/callback"?ce(o,r):o.pathname==="/"?(r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>freee MCP OAuth Server</h1><p>\u30B3\u30FC\u30EB\u30D0\u30C3\u30AF\u30B5\u30FC\u30D0\u30FC\u304C\u7A3C\u50CD\u4E2D\u3067\u3059\u3002</p>")):(r.writeHead(404,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>404 Not Found</h1><p>\u3053\u306E\u30D1\u30B9\u306F\u5B58\u5728\u3057\u307E\u305B\u3093\u3002</p>"))}),f.on("error",a=>{console.error("Callback server error:",a),i(a)}),f.listen(t,"127.0.0.1",()=>{console.error(`\u{1F517} OAuth callback server listening on http://127.0.0.1:${t}`),n()})})}function G(t,e){console.error(`\u{1F510} Registering authentication request with state: ${t.substring(0,10)}...`),console.error(`\u{1F510} Code verifier: ${e.substring(0,10)}...`);let n=setTimeout(()=>{_.delete(t),console.error(`\u23F0 Authentication timeout for state: ${t.substring(0,10)}...`)},p.auth.timeoutMs);_.set(t,{codeVerifier:e,resolve:i=>{console.error("\u{1F389} Authentication completed successfully!")},reject:i=>{console.error("\u274C Authentication failed:",i)},timeout:n}),console.error(`\u{1F4DD} Registration complete. Total pending: ${_.size}`)}function P(){if(f){for(let[t,e]of _)clearTimeout(e.timeout),e.reject(new Error("Server shutdown"));_.clear(),f.close(()=>{console.error("\u{1F534} OAuth callback server stopped")}),f=null}}function ce(t,e){let n=t.searchParams.get("code"),i=t.searchParams.get("state"),a=t.searchParams.get("error"),r=t.searchParams.get("error_description");if(console.error(`\u{1F50D} Callback received - URL: ${t.toString()}`),console.error("\u{1F50D} Callback parameters:",{code:n?`${n.substring(0,10)}...`:null,state:i?`${i.substring(0,10)}...`:null,error:a,errorDescription:r}),console.error(`\u{1F50D} Pending authentications count: ${_.size}`),a){let s=r||a;if(console.error(`\u274C OAuth error: ${a} - ${r}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end(`<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${s}</p>`),i&&_.has(i)){let c=_.get(i);clearTimeout(c.timeout),c.reject(new Error(`OAuth error: ${a} - ${r}`)),_.delete(i)}return}if(!n||!i){console.error("\u274C Missing code or state"),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u30B3\u30FC\u30C9\u307E\u305F\u306F\u72B6\u614B\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002</p>");return}let o=_.get(i);if(!o){console.error(`\u274C Unknown state: ${i}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u4E0D\u660E\u306A\u8A8D\u8A3C\u72B6\u614B\u3067\u3059\u3002\u8A8D\u8A3C\u3092\u518D\u958B\u3057\u3066\u304F\u3060\u3055\u3044\u3002</p>");return}console.error("\u2705 Valid callback received, exchanging code for tokens..."),e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u5B8C\u4E86</h1><p>\u8A8D\u8A3C\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002\u3053\u306E\u30DA\u30FC\u30B8\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002</p>"),clearTimeout(o.timeout),_.delete(i),W(n,o.codeVerifier).then(s=>{console.error("\u{1F389} Token exchange successful!"),o.resolve(s)}).catch(s=>{console.error("\u274C Token exchange failed:",s),o.reject(s)})}import ue from"crypto";import{z as C}from"zod";import T from"fs/promises";import A from"path";import le from"os";function S(){let t=A.join(le.homedir(),".config","freee-mcp");return A.join(t,"config.json")}async function de(){let t=A.dirname(S());await T.mkdir(t,{recursive:!0})}async function $(){let t=S();try{let e=await T.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=p.freee.companyId||"0",i={defaultCompanyId:n,currentCompanyId:n,companies:{[n]:{id:n,name:"Default Company",description:"Company from environment variable",addedAt:Date.now(),lastUsed:Date.now()}}};return await V(i),i}throw e}}async function V(t){await de();let e=S();await T.writeFile(e,JSON.stringify(t,null,2),{mode:384})}async function g(){return(await $()).currentCompanyId}async function Z(t,e,n){let i=await $();i.companies[t]?(e||n)&&(e&&(i.companies[t].name=e),n&&(i.companies[t].description=n)):i.companies[t]={id:t,name:e||`Company ${t}`,description:n||void 0,addedAt:Date.now()},i.companies[t].lastUsed=Date.now(),i.currentCompanyId=t,await V(i)}async function E(){let t=await $();return Object.values(t.companies).sort((e,n)=>(n.lastUsed||0)-(e.lastUsed||0))}async function q(t){return(await $()).companies[t]||null}async function w(t,e,n,i){let a=p.freee.apiUrl,r=await g(),o=await U();if(!o)throw new Error(`\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
1
|
+
import{McpServer as xe}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as be}from"@modelcontextprotocol/sdk/server/stdio.js";var U=parseInt(process.env.FREEE_CALLBACK_PORT||"8080",10),p={freee:{clientId:process.env.FREEE_CLIENT_ID||"",clientSecret:process.env.FREEE_CLIENT_SECRET||"",companyId:process.env.FREEE_COMPANY_ID||"0",apiUrl:"https://api.freee.co.jp"},oauth:{callbackPort:U,redirectUri:`http://127.0.0.1:${U}/callback`,authorizationEndpoint:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenEndpoint:"https://accounts.secure.freee.co.jp/public_api/token",scope:"read write"},server:{name:"freee",version:"1.0.0"},auth:{timeoutMs:5*60*1e3}};import se from"http";import{URL as me}from"url";import ce from"net";import B from"crypto";import y from"fs/promises";import h from"path";import R from"os";function P(){let t=h.join(R.homedir(),".config","freee-mcp");return h.join(t,"tokens.json")}async function v(t){let e=P(),n=h.dirname(e);try{console.error(`\u{1F4C1} Creating directory: ${n}`),await y.mkdir(n,{recursive:!0}),console.error(`\u{1F4BE} Writing tokens to: ${e}`),await y.writeFile(e,JSON.stringify(t,null,2),{mode:384}),console.error("\u2705 Tokens saved successfully")}catch(i){throw console.error("\u274C Failed to save tokens:",i),i}}async function I(){let t=P();try{let e=await y.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=await ae();return n||null}throw console.error("Failed to load tokens:",e),e}}function re(t){return Date.now()<t.expires_at}async function ae(){let t=h.join(R.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));if(n.length>0){let i=h.join(t,n[0]),a=await y.readFile(i,"utf8"),r=JSON.parse(a);return await v(r),await Promise.all(n.map(o=>y.unlink(h.join(t,o)).catch(()=>{}))),console.error("\u2705 Migrated legacy company-specific tokens to user-based tokens"),r}}catch{}return null}async function oe(t){let e=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:t,client_id:p.freee.clientId,client_secret:p.freee.clientSecret})});if(!e.ok){let a=await e.json().catch(()=>({}));throw new Error(`Token refresh failed: ${e.status} ${JSON.stringify(a)}`)}let n=await e.json(),i={access_token:n.access_token,refresh_token:n.refresh_token||t,expires_at:Date.now()+n.expires_in*1e3,token_type:n.token_type||"Bearer",scope:n.scope||p.oauth.scope};return await v(i),i}async function O(){let t=P();try{await y.unlink(t),console.error("Tokens cleared successfully")}catch(e){if(e.code==="ENOENT"){console.error("No tokens to clear (file does not exist)");return}throw console.error("Failed to clear tokens:",e),e}await pe()}async function pe(){let t=h.join(R.homedir(),".config","freee-mcp");try{let n=(await y.readdir(t)).filter(i=>i.startsWith("tokens-")&&i.endsWith(".json"));await Promise.all(n.map(i=>y.unlink(h.join(t,i)).catch(()=>{}))),n.length>0&&console.error("\u2705 Cleared legacy company-specific token files")}catch{}}async function J(){let t=await I();if(!t)return null;if(re(t))return t.access_token;try{return(await oe(t.refresh_token)).access_token}catch(e){return console.error("Failed to refresh token:",e),null}}function W(){let t=B.randomBytes(32).toString("base64url"),e=B.createHash("sha256").update(t).digest("base64url");return{codeVerifier:t,codeChallenge:e}}function M(t,e,n){let i=new URLSearchParams({response_type:"code",client_id:p.freee.clientId,redirect_uri:n,scope:p.oauth.scope,state:e,code_challenge:t,code_challenge_method:"S256"});return`${p.oauth.authorizationEndpoint}?${i.toString()}`}async function G(t,e,n){let i=await fetch(p.oauth.tokenEndpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:p.freee.clientId,client_secret:p.freee.clientSecret,code:t,redirect_uri:n,code_verifier:e})});if(!i.ok){let o=await i.json().catch(()=>({}));throw new Error(`Token exchange failed: ${i.status} ${JSON.stringify(o)}`)}let a=await i.json(),r={access_token:a.access_token,refresh_token:a.refresh_token,expires_at:Date.now()+a.expires_in*1e3,token_type:a.token_type||"Bearer",scope:a.scope||p.oauth.scope};return await v(r),r}var f=null,$=null,_=new Map;async function le(t){return new Promise(e=>{let n=ce.createServer();n.listen(t,"127.0.0.1",()=>{n.close(()=>{e(!0)})}),n.on("error",()=>{e(!1)})})}async function de(t,e=50){for(let n=t;n<t+e;n++)if(await le(n))return n;throw new Error(`No available port found after checking ${e} ports starting from ${t}`)}function A(){if($===null)throw new Error("Callback server not started. Call startCallbackServer() first.");return`http://127.0.0.1:${$}/callback`}async function V(){if(f)return;let t=p.oauth.callbackPort,e=await de(t);return $=e,e!==t&&console.error(`\u26A0\uFE0F Port ${t} is in use. Using fallback port ${e} for OAuth callback server.`),new Promise((n,i)=>{f=se.createServer((a,r)=>{console.error(`\u{1F4E5} Callback request: ${a.method} ${a.url}`);let o=new me(a.url,`http://127.0.0.1:${e}`);o.pathname==="/callback"?ue(o,r):o.pathname==="/"?(r.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>freee MCP OAuth Server</h1><p>\u30B3\u30FC\u30EB\u30D0\u30C3\u30AF\u30B5\u30FC\u30D0\u30FC\u304C\u7A3C\u50CD\u4E2D\u3067\u3059\u3002</p>")):(r.writeHead(404,{"Content-Type":"text/html; charset=utf-8"}),r.end("<h1>404 Not Found</h1><p>\u3053\u306E\u30D1\u30B9\u306F\u5B58\u5728\u3057\u307E\u305B\u3093\u3002</p>"))}),f.on("error",a=>{console.error("Callback server error:",a),i(a)}),f.listen(e,"127.0.0.1",()=>{console.error(`\u{1F517} OAuth callback server listening on http://127.0.0.1:${e}`),n()})})}function Z(t,e){console.error(`\u{1F510} Registering authentication request with state: ${t.substring(0,10)}...`),console.error(`\u{1F510} Code verifier: ${e.substring(0,10)}...`);let n=setTimeout(()=>{_.delete(t),console.error(`\u23F0 Authentication timeout for state: ${t.substring(0,10)}...`)},p.auth.timeoutMs);_.set(t,{codeVerifier:e,resolve:i=>{console.error("\u{1F389} Authentication completed successfully!")},reject:i=>{console.error("\u274C Authentication failed:",i)},timeout:n}),console.error(`\u{1F4DD} Registration complete. Total pending: ${_.size}`)}function T(){if(f){for(let[t,e]of _)clearTimeout(e.timeout),e.reject(new Error("Server shutdown"));_.clear(),f.close(()=>{console.error("\u{1F534} OAuth callback server stopped")}),f=null,$=null}}function ue(t,e){let n=t.searchParams.get("code"),i=t.searchParams.get("state"),a=t.searchParams.get("error"),r=t.searchParams.get("error_description");if(console.error(`\u{1F50D} Callback received - URL: ${t.toString()}`),console.error("\u{1F50D} Callback parameters:",{code:n?`${n.substring(0,10)}...`:null,state:i?`${i.substring(0,10)}...`:null,error:a,errorDescription:r}),console.error(`\u{1F50D} Pending authentications count: ${_.size}`),a){let s=r||a;if(console.error(`\u274C OAuth error: ${a} - ${r}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end(`<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${s}</p>`),i&&_.has(i)){let c=_.get(i);clearTimeout(c.timeout),c.reject(new Error(`OAuth error: ${a} - ${r}`)),_.delete(i)}return}if(!n||!i){console.error("\u274C Missing code or state"),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u8A8D\u8A3C\u30B3\u30FC\u30C9\u307E\u305F\u306F\u72B6\u614B\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059\u3002</p>");return}let o=_.get(i);if(!o){console.error(`\u274C Unknown state: ${i}`),e.writeHead(400,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u30A8\u30E9\u30FC</h1><p>\u4E0D\u660E\u306A\u8A8D\u8A3C\u72B6\u614B\u3067\u3059\u3002\u8A8D\u8A3C\u3092\u518D\u958B\u3057\u3066\u304F\u3060\u3055\u3044\u3002</p>");return}console.error("\u2705 Valid callback received, exchanging code for tokens..."),e.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),e.end("<h1>\u8A8D\u8A3C\u5B8C\u4E86</h1><p>\u8A8D\u8A3C\u304C\u5B8C\u4E86\u3057\u307E\u3057\u305F\u3002\u3053\u306E\u30DA\u30FC\u30B8\u3092\u9589\u3058\u3066\u304F\u3060\u3055\u3044\u3002</p>"),clearTimeout(o.timeout),_.delete(i),G(n,o.codeVerifier,A()).then(s=>{console.error("\u{1F389} Token exchange successful!"),o.resolve(s)}).catch(s=>{console.error("\u274C Token exchange failed:",s),o.reject(s)})}import ge from"crypto";import{z}from"zod";import C from"fs/promises";import S from"path";import _e from"os";function L(){let t=S.join(_e.homedir(),".config","freee-mcp");return S.join(t,"config.json")}async function ye(){let t=S.dirname(L());await C.mkdir(t,{recursive:!0})}async function E(){let t=L();try{let e=await C.readFile(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT"){let n=p.freee.companyId||"0",i={defaultCompanyId:n,currentCompanyId:n,companies:{[n]:{id:n,name:"Default Company",description:"Company from environment variable",addedAt:Date.now(),lastUsed:Date.now()}}};return await Y(i),i}throw e}}async function Y(t){await ye();let e=L();await C.writeFile(e,JSON.stringify(t,null,2),{mode:384})}async function g(){return(await E()).currentCompanyId}async function H(t,e,n){let i=await E();i.companies[t]?(e||n)&&(e&&(i.companies[t].name=e),n&&(i.companies[t].description=n)):i.companies[t]={id:t,name:e||`Company ${t}`,description:n||void 0,addedAt:Date.now()},i.companies[t].lastUsed=Date.now(),i.currentCompanyId=t,await Y(i)}async function k(){let t=await E();return Object.values(t.companies).sort((e,n)=>(n.lastUsed||0)-(e.lastUsed||0))}async function q(t){return(await E()).companies[t]||null}async function w(t,e,n,i){let a=p.freee.apiUrl,r=await g(),o=await J();if(!o)throw new Error(`\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
2
2
|
\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${r}
|
|
3
3
|
\u307E\u305F\u306F\u3001FREEE_CLIENT_ID\u74B0\u5883\u5909\u6570\u304C\u6B63\u3057\u304F\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u304B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);let s=new URL(e,a);n&&Object.entries(n).forEach(([m,d])=>{d!==void 0&&s.searchParams.append(m,String(d))}),s.searchParams.append("company_id",String(r));let c=await fetch(s.toString(),{method:t,headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:i?JSON.stringify(typeof i=="string"?JSON.parse(i):i):void 0});if(c.status===401||c.status===403){let m=await c.json().catch(()=>({}));throw new Error(`\u8A8D\u8A3C\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u518D\u8A8D\u8A3C\u3092\u884C\u3063\u3066\u304F\u3060\u3055\u3044\u3002
|
|
4
4
|
\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${r}
|
|
@@ -18,7 +18,7 @@ ${x.join(`
|
|
|
18
18
|
\u65E2\u5B58\u306E\u30C7\u30FC\u30BF\u3092\u53D6\u5F97\u3057\u3066\u6B63\u3057\u3044\u69CB\u9020\u3092\u78BA\u8A8D\u3059\u308B\u3053\u3068\u3092\u304A\u52E7\u3081\u3057\u307E\u3059\u3002`,d+=`
|
|
19
19
|
\u4F8B: get_items, get_partners, get_account_items \u306A\u3069\u3067\u65E2\u5B58\u30C7\u30FC\u30BF\u306E\u69CB\u9020\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`))}throw m?.errors||(d+=`
|
|
20
20
|
|
|
21
|
-
\u8A73\u7D30: ${JSON.stringify(m)}`),new Error(d)}return c.json()}function
|
|
21
|
+
\u8A73\u7D30: ${JSON.stringify(m)}`),new Error(d)}return c.json()}function K(t){t.tool("freee_current_user","freee API\u306E\u73FE\u5728\u306E\u30E6\u30FC\u30B6\u30FC\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u8A8D\u8A3C\u72B6\u614B\u3001\u4E8B\u696D\u6240ID\u3001\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30\u304C\u542B\u307E\u308C\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30C6\u30B9\u30C8\u7528\u30FBAPI\u52D5\u4F5C\u78BA\u8A8D\u306B\u6700\u9069\u3011",{},async()=>{try{let e=await g(),n=await q(e);if(!e)return{content:[{type:"text",text:"\u4F1A\u793EID\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002freee_set_company \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u4F1A\u793E\u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"}]};let i=await w("GET","/api/1/users/me");return{content:[{type:"text",text:`\u73FE\u5728\u306E\u30E6\u30FC\u30B6\u30FC\u60C5\u5831:
|
|
22
22
|
\u73FE\u5728\u306E\u4F1A\u793EID: ${e}
|
|
23
23
|
\u4F1A\u793E\u540D: ${n?.name||"Unknown"}
|
|
24
24
|
\u30E6\u30FC\u30B6\u30FC\u8A73\u7D30:
|
|
@@ -33,7 +33,7 @@ ${JSON.stringify(i,null,2)}`}]}}catch(e){return{content:[{type:"text",text:`\u30
|
|
|
33
33
|
OAuth\u8A8D\u8A3C\u3092\u884C\u3046\u306B\u306F\u3001freee developers\u3067\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3057\u3001
|
|
34
34
|
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8ID\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};if(!p.freee.clientSecret)return{content:[{type:"text",text:`FREEE_CLIENT_SECRET\u74B0\u5883\u5909\u6570\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002
|
|
35
35
|
OAuth\u8A8D\u8A3C\u3092\u884C\u3046\u306B\u306F\u3001freee developers\u3067\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3092\u4F5C\u6210\u3057\u3001
|
|
36
|
-
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let{codeVerifier:e,codeChallenge:n}=
|
|
36
|
+
\u30AF\u30E9\u30A4\u30A2\u30F3\u30C8\u30B7\u30FC\u30AF\u30EC\u30C3\u30C8\u3092\u74B0\u5883\u5909\u6570\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let{codeVerifier:e,codeChallenge:n}=W(),i=ge.randomBytes(16).toString("hex"),a=M(n,i,A());return Z(i,e),console.error(`\u{1F310} Authentication URL: ${a}`),{content:[{type:"text",text:`\u{1F680} OAuth\u8A8D\u8A3C\u3092\u958B\u59CB\u3057\u307E\u3057\u305F\uFF01
|
|
37
37
|
|
|
38
38
|
\u{1F4F1} \u8A8D\u8A3CURL\u3092\u751F\u6210\u3057\u307E\u3057\u305F\u3002\u30D6\u30E9\u30A6\u30B6\u3067\u4EE5\u4E0B\u306EURL\u3092\u958B\u3044\u3066\u8A8D\u8A3C\u3092\u5B8C\u4E86\u3057\u3066\u304F\u3060\u3055\u3044:
|
|
39
39
|
${a}
|
|
@@ -66,21 +66,21 @@ ${a}
|
|
|
66
66
|
|
|
67
67
|
\u{1F527} \u89E3\u6C7A\u624B\u9806:
|
|
68
68
|
1. freee_status - \u5168\u4F53\u7684\u306A\u72B6\u614B\u3092\u78BA\u8A8D
|
|
69
|
-
2. freee_getting_started - \u521D\u671F\u8A2D\u5B9A\u30AC\u30A4\u30C9`}]}}}),t.tool("freee_clear_auth","freee API\u306E\u8A8D\u8A3C\u60C5\u5831\u3092\u30AF\u30EA\u30A2\u3057\u307E\u3059\u3002\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u30C8\u30FC\u30AF\u30F3\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3057\u3001\u6B21\u56DEAPI\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u306B\u306A\u308A\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30A8\u30E9\u30FC\u6642\u306E\u30EA\u30BB\u30C3\u30C8\u7528\u3011",{},async()=>{try{return await
|
|
69
|
+
2. freee_getting_started - \u521D\u671F\u8A2D\u5B9A\u30AC\u30A4\u30C9`}]}}}),t.tool("freee_clear_auth","freee API\u306E\u8A8D\u8A3C\u60C5\u5831\u3092\u30AF\u30EA\u30A2\u3057\u307E\u3059\u3002\u4FDD\u5B58\u3055\u308C\u3066\u3044\u308B\u30C8\u30FC\u30AF\u30F3\u30D5\u30A1\u30A4\u30EB\u3092\u524A\u9664\u3057\u3001\u6B21\u56DEAPI\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u306B\u306A\u308A\u307E\u3059\u3002\u3010\u8A8D\u8A3C\u30A8\u30E9\u30FC\u6642\u306E\u30EA\u30BB\u30C3\u30C8\u7528\u3011",{},async()=>{try{return await O(),{content:[{type:"text",text:`\u8A8D\u8A3C\u60C5\u5831\u304C\u30AF\u30EA\u30A2\u3055\u308C\u307E\u3057\u305F\u3002
|
|
70
70
|
\u6B21\u56DEfreee API\u4F7F\u7528\u6642\u306B\u518D\u8A8D\u8A3C\u304C\u5FC5\u8981\u3067\u3059\u3002
|
|
71
71
|
\u518D\u8A8D\u8A3C\u3059\u308B\u306B\u306F freee_authenticate \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u8A8D\u8A3C\u60C5\u5831\u306E\u30AF\u30EA\u30A2\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
72
72
|
|
|
73
73
|
\u{1F527} \u4EE3\u66FF\u624B\u9806:
|
|
74
74
|
1. freee_status - \u72B6\u614B\u3092\u78BA\u8A8D
|
|
75
|
-
2. \u624B\u52D5\u3067\u30D5\u30A1\u30A4\u30EB\u524A\u9664: ~/.config/freee-mcp/tokens.json`}]}}}),t.tool("freee_set_company","\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\u30FB\u5207\u308A\u66FF\u3048\u307E\u3059\u3002\u65B0\u3057\u3044\u4E8B\u696D\u6240\u306E\u5834\u5408\u306F\u81EA\u52D5\u7684\u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",{company_id:
|
|
75
|
+
2. \u624B\u52D5\u3067\u30D5\u30A1\u30A4\u30EB\u524A\u9664: ~/.config/freee-mcp/tokens.json`}]}}}),t.tool("freee_set_company","\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\u30FB\u5207\u308A\u66FF\u3048\u307E\u3059\u3002\u65B0\u3057\u3044\u4E8B\u696D\u6240\u306E\u5834\u5408\u306F\u81EA\u52D5\u7684\u306B\u8FFD\u52A0\u3055\u308C\u307E\u3059\u3002\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\u306F\u305D\u306E\u307E\u307E\u4F7F\u7528\u3067\u304D\u307E\u3059\u3002",{company_id:z.string().describe("\u4E8B\u696D\u6240ID\uFF08\u5FC5\u9808\uFF09"),name:z.string().optional().describe("\u4E8B\u696D\u6240\u540D\uFF08\u30AA\u30D7\u30B7\u30E7\u30F3\u3001\u65B0\u898F\u8FFD\u52A0\u6642\u306B\u8A2D\u5B9A\uFF09"),description:z.string().optional().describe("\u4E8B\u696D\u6240\u306E\u8AAC\u660E\uFF08\u30AA\u30D7\u30B7\u30E7\u30F3\uFF09")},async e=>{try{let{company_id:n,name:i,description:a}=e;await H(n,i,a);let r=await q(n);return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u3092\u5207\u308A\u66FF\u3048\u307E\u3057\u305F:\\n\u4E8B\u696D\u6240ID: ${n}\\n\u4E8B\u696D\u6240\u540D: ${r?.name||"Unknown"}\\n\u8AAC\u660E: ${r?.description||"\u306A\u3057"}\\n\\n\u{1F680} \u3053\u306E\u4E8B\u696D\u6240\u3067\u3059\u3050\u306BAPI\u3092\u4F7F\u7528\u3067\u304D\u307E\u3059\uFF08\u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408\uFF09\u3002
|
|
76
76
|
|
|
77
77
|
\u{1F4A1} \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
|
|
78
78
|
\u30FB \u8A8D\u8A3C\u6E08\u307F\u306E\u5834\u5408: freee_current_user \u3067\u30C6\u30B9\u30C8
|
|
79
|
-
\u30FB \u672A\u8A8D\u8A3C\u306E\u5834\u5408: freee_authenticate \u3067\u8A8D\u8A3C`}]}}catch(n){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n instanceof Error?n.message:String(n)}`}]}}}),t.tool("freee_get_current_company","\u73FE\u5728\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u4E8B\u696D\u6240\u306E\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u3010\u73FE\u5728\u306E\u4F5C\u696D\u5BFE\u8C61\u4E8B\u696D\u6240\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await g(),n=await q(e);return n?{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240\u60C5\u5831:\\n\u4E8B\u696D\u6240ID: ${n.id}\\n\u4E8B\u696D\u6240\u540D: ${n.name}\\n\u8AAC\u660E: ${n.description||"\u306A\u3057"}\\n\u8FFD\u52A0\u65E5\u6642: ${new Date(n.addedAt).toLocaleString()}\\n\u6700\u7D42\u4F7F\u7528: ${n.lastUsed?new Date(n.lastUsed).toLocaleString():"\u306A\u3057"}`}]}:{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${e}\\n\u4E8B\u696D\u6240\u60C5\u5831\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}`}]}}}),t.tool("freee_list_companies","\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u5185\u90E8\u7684\u306Bget_companies\u3092\u547C\u3073\u51FA\u3057\u3066freee API\u304B\u3089\u6700\u65B0\u306E\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u3010\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\u524D\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await w("GET","/api/1/companies"),n=await
|
|
79
|
+
\u30FB \u672A\u8A8D\u8A3C\u306E\u5834\u5408: freee_authenticate \u3067\u8A8D\u8A3C`}]}}catch(n){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u306E\u8A2D\u5B9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${n instanceof Error?n.message:String(n)}`}]}}}),t.tool("freee_get_current_company","\u73FE\u5728\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u308B\u4E8B\u696D\u6240\u306E\u60C5\u5831\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u3010\u73FE\u5728\u306E\u4F5C\u696D\u5BFE\u8C61\u4E8B\u696D\u6240\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await g(),n=await q(e);return n?{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240\u60C5\u5831:\\n\u4E8B\u696D\u6240ID: ${n.id}\\n\u4E8B\u696D\u6240\u540D: ${n.name}\\n\u8AAC\u660E: ${n.description||"\u306A\u3057"}\\n\u8FFD\u52A0\u65E5\u6642: ${new Date(n.addedAt).toLocaleString()}\\n\u6700\u7D42\u4F7F\u7528: ${n.lastUsed?new Date(n.lastUsed).toLocaleString():"\u306A\u3057"}`}]}:{content:[{type:"text",text:`\u73FE\u5728\u306E\u4E8B\u696D\u6240ID: ${e}\\n\u4E8B\u696D\u6240\u60C5\u5831\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`}]}}catch(e){return{content:[{type:"text",text:`\u4E8B\u696D\u6240\u60C5\u5831\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}`}]}}}),t.tool("freee_list_companies","\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u8868\u793A\u3057\u307E\u3059\u3002\u5185\u90E8\u7684\u306Bget_companies\u3092\u547C\u3073\u51FA\u3057\u3066freee API\u304B\u3089\u6700\u65B0\u306E\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3057\u307E\u3059\u3002\u3010\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\u524D\u306E\u78BA\u8A8D\u7528\u3011",{},async()=>{try{let e=await w("GET","/api/1/companies"),n=await k(),i=await g();if(!e||!e.companies||e.companies.length===0)return{content:[{type:"text",text:`freee API\u304B\u3089\u4E8B\u696D\u6240\u60C5\u5831\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u8A8D\u8A3C\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002
|
|
80
80
|
|
|
81
81
|
\u{1F4A1} \u6B21\u306E\u30B9\u30C6\u30C3\u30D7:
|
|
82
82
|
1. freee_auth_status - \u8A8D\u8A3C\u72B6\u614B\u3092\u78BA\u8A8D
|
|
83
|
-
2. freee_authenticate - \u8A8D\u8A3C\u3092\u5B9F\u884C`}]};let a=e.companies.map(r=>{let o=r.id===parseInt(i)?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=n.find(m=>m.id===r.id.toString()),c=s?.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(s.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${r.name} (ID: ${r.id})${o}\\n \u8AAC\u660E: ${r.description||"\u306A\u3057"}\\n ${c}`}).join("\\n\\n");return{content:[{type:"text",text:`freee API\u4E8B\u696D\u6240\u4E00\u89A7 (${e.companies.length}\u4EF6):\\n\\n${a}`}]}}catch(e){try{let n=await
|
|
83
|
+
2. freee_authenticate - \u8A8D\u8A3C\u3092\u5B9F\u884C`}]};let a=e.companies.map(r=>{let o=r.id===parseInt(i)?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=n.find(m=>m.id===r.id.toString()),c=s?.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(s.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${r.name} (ID: ${r.id})${o}\\n \u8AAC\u660E: ${r.description||"\u306A\u3057"}\\n ${c}`}).join("\\n\\n");return{content:[{type:"text",text:`freee API\u4E8B\u696D\u6240\u4E00\u89A7 (${e.companies.length}\u4EF6):\\n\\n${a}`}]}}catch(e){try{let n=await k(),i=await g();if(n.length===0)return{content:[{type:"text",text:`API\u547C\u3073\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
84
84
|
|
|
85
85
|
\u8A2D\u5B9A\u6E08\u307F\u306E\u4E8B\u696D\u6240\u3082\u3042\u308A\u307E\u305B\u3093\u3002freee_set_company \u30C4\u30FC\u30EB\u3092\u4F7F\u7528\u3057\u3066\u4E8B\u696D\u6240\u3092\u8FFD\u52A0\u3057\u3066\u304F\u3060\u3055\u3044\u3002`}]};let a=n.map(r=>{let o=r.id===i?" (\u73FE\u5728\u9078\u629E\u4E2D)":"",s=r.lastUsed?`\u6700\u7D42\u4F7F\u7528: ${new Date(r.lastUsed).toLocaleString()}`:"\u672A\u4F7F\u7528";return`\u2022 ${r.name} (ID: ${r.id})${o}\\n \u8AAC\u660E: ${r.description||"\u306A\u3057"}\\n ${s}`}).join("\\n\\n");return{content:[{type:"text",text:`API\u547C\u3073\u51FA\u3057\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}
|
|
86
86
|
|
|
@@ -203,7 +203,7 @@ freee_set_company [\u4E8B\u696D\u6240ID] # \u5207\u308A\u66FF\u3048
|
|
|
203
203
|
|
|
204
204
|
### \u4E8B\u696D\u6240ID\u304C\u5206\u304B\u3089\u306A\u3044\u5834\u5408
|
|
205
205
|
1. freee\u753B\u9762\u306EURL\u304B\u3089\u78BA\u8A8D\uFF08\u4F8B: /companies/12345/...\uFF09
|
|
206
|
-
2. \u65E2\u5B58\u306E\u8A8D\u8A3C\u304C\u3042\u308C\u3070 \`freee_current_user\` \u3067\u78BA\u8A8D\u53EF\u80FD`}]}}catch(e){return{content:[{type:"text",text:`\u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9\u306E\u8868\u793A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u307E\u305A\u306F\u74B0\u5883\u5909\u6570\u306E\u8A2D\u5B9A\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044\u3002`}]}}}),t.tool("freee_status","\u73FE\u5728\u306Efreee MCP \u30B5\u30FC\u30D0\u30FC\u306E\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3001\u6B21\u306B\u5B9F\u884C\u3059\u3079\u304D\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u63D0\u6848\u3057\u307E\u3059\u3002",{},async()=>{try{let e=await g(),n=await q(e),i=await I(),a=await
|
|
206
|
+
2. \u65E2\u5B58\u306E\u8A8D\u8A3C\u304C\u3042\u308C\u3070 \`freee_current_user\` \u3067\u78BA\u8A8D\u53EF\u80FD`}]}}catch(e){return{content:[{type:"text",text:`\u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9\u306E\u8868\u793A\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u307E\u305A\u306F\u74B0\u5883\u5909\u6570\u306E\u8A2D\u5B9A\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044\u3002`}]}}}),t.tool("freee_status","\u73FE\u5728\u306Efreee MCP \u30B5\u30FC\u30D0\u30FC\u306E\u72B6\u614B\u3092\u78BA\u8A8D\u3057\u3001\u6B21\u306B\u5B9F\u884C\u3059\u3079\u304D\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u63D0\u6848\u3057\u307E\u3059\u3002",{},async()=>{try{let e=await g(),n=await q(e),i=await I(),a=await k(),r="",o="",s="";if(!e||e==="0"?(r+="\u274C **\u4E8B\u696D\u6240**: \u672A\u8A2D\u5B9A\\n",o+="\u2022 freee_set_company [\u4E8B\u696D\u6240ID] \u3067\u4E8B\u696D\u6240\u3092\u8A2D\u5B9A\\n"):n?r+=`\u2705 **\u4E8B\u696D\u6240**: ${n.name} (ID: ${n.id})\\n`:(r+="\u26A0\uFE0F **\u4E8B\u696D\u6240**: \u8A2D\u5B9A\u4E0D\u5B8C\u5168\\n",o+="\u2022 freee_set_company \u3067\u4E8B\u696D\u6240\u60C5\u5831\u3092\u518D\u8A2D\u5B9A\\n"),!i)r+="\u274C **\u8A8D\u8A3C**: \u672A\u8A8D\u8A3C\\n",o+="\u2022 freee_authenticate \u3067\u8A8D\u8A3C\u3092\u5B9F\u884C\\n";else{let c=Date.now()<i.expires_at,m=new Date(i.expires_at).toLocaleString();c?(r+=`\u2705 **\u8A8D\u8A3C**: \u6709\u52B9 (\u671F\u9650: ${m})\\n`,o+="\u2022 freee_current_user \u3067\u30C6\u30B9\u30C8\u5B9F\u884C\\n\u2022 get_deals, get_companies \u306A\u3069\u306EAPI\u30C4\u30FC\u30EB\u304C\u4F7F\u7528\u53EF\u80FD\\n"):(r+=`\u26A0\uFE0F **\u8A8D\u8A3C**: \u671F\u9650\u5207\u308C (${m})\\n`,o+="\u2022 \u6B21\u56DEAPI\u5B9F\u884C\u6642\u306B\u81EA\u52D5\u66F4\u65B0\u3055\u308C\u307E\u3059\\n\u2022 \u624B\u52D5\u66F4\u65B0: freee_authenticate\\n")}return r+=`\u{1F4CA} **\u767B\u9332\u4E8B\u696D\u6240\u6570**: ${a.length}\u4EF6\\n`,a.length>1?o+="\u2022 freee_list_companies \u3067\u4E8B\u696D\u6240\u4E00\u89A7\u3092\u78BA\u8A8D\\n\u2022 freee_set_company [ID] \u3067\u4E8B\u696D\u6240\u5207\u308A\u66FF\u3048\\n":a.length===1&&(o+="\u2022 freee_set_company [\u65B0\u3057\u3044ID] \u3067\u8FFD\u52A0\u4E8B\u696D\u6240\u3092\u767B\u9332\u53EF\u80FD\\n"),(!p.freee.clientId||!p.freee.clientSecret)&&(s+="\u26A0\uFE0F **\u74B0\u5883\u5909\u6570**: FREEE_CLIENT_ID \u307E\u305F\u306F FREEE_CLIENT_SECRET \u304C\u672A\u8A2D\u5B9A\\n"),e&&n&&i&&Date.now()<i.expires_at&&(o+="\\n\u{1F680} **\u3059\u3050\u306B\u4F7F\u7528\u53EF\u80FD**: freee API\u30C4\u30FC\u30EB\u304C\u5229\u7528\u3067\u304D\u307E\u3059\\n",o+="**\u4F8B**: get_deals, get_companies, get_users, \u306A\u3069"),{content:[{type:"text",text:`# freee MCP \u30B5\u30FC\u30D0\u30FC \u72B6\u614B\u78BA\u8A8D
|
|
207
207
|
|
|
208
208
|
## \u{1F4CA} \u73FE\u5728\u306E\u72B6\u614B
|
|
209
209
|
${r}
|
|
@@ -216,7 +216,7 @@ ${o}
|
|
|
216
216
|
- \`freee_help\` - \u5168\u4F53\u7684\u306A\u4F7F\u3044\u65B9\u30AC\u30A4\u30C9
|
|
217
217
|
- \`freee_getting_started\` - \u521D\u56DE\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u30AC\u30A4\u30C9
|
|
218
218
|
- \`freee_list_companies\` - \u4E8B\u696D\u6240\u4E00\u89A7
|
|
219
|
-
- \`freee_auth_status\` - \u8A8D\u8A3C\u72B6\u614B\u306E\u8A73\u7D30`}]}}catch(e){return{content:[{type:"text",text:`\u72B6\u614B\u78BA\u8A8D\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u57FA\u672C\u7684\u306A\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044:\\n1. freee_getting_started\\n2. freee_set_company [\u4E8B\u696D\u6240ID]\\n3. freee_authenticate`}]}}})}import{z as
|
|
219
|
+
- \`freee_auth_status\` - \u8A8D\u8A3C\u72B6\u614B\u306E\u8A73\u7D30`}]}}catch(e){return{content:[{type:"text",text:`\u72B6\u614B\u78BA\u8A8D\u4E2D\u306B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F: ${e instanceof Error?e.message:String(e)}\\n\\n\u57FA\u672C\u7684\u306A\u30BB\u30C3\u30C8\u30A2\u30C3\u30D7\u304B\u3089\u59CB\u3081\u3066\u304F\u3060\u3055\u3044:\\n1. freee_getting_started\\n2. freee_set_company [\u4E8B\u696D\u6240ID]\\n3. freee_authenticate`}]}}})}import{z as fe}from"zod";var Q={openapi:"3.0.1",info:{title:"freee\u4F1A\u8A08 API",description:`
|
|
220
220
|
<hr />
|
|
221
221
|
<h2 id="start_guide">\u30B9\u30BF\u30FC\u30C8\u30AC\u30A4\u30C9</h2>
|
|
222
222
|
|
|
@@ -4985,4 +4985,4 @@ submitted \u306F\u8ACB\u6C42\u66F8\u627F\u8A8D\u30EF\u30FC\u30AF\u30D5\u30ED\u30
|
|
|
4985
4985
|
<ul>
|
|
4986
4986
|
<li>normal\u3001discount\u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u3001account_item_id,tax_code\u3068unit_price\u304C\u5FC5\u9808\u3068\u306A\u308A\u307E\u3059\u3002</li>
|
|
4987
4987
|
<li>normal\u3092\u6307\u5B9A\u3057\u305F\u5834\u5408\u3001qty\u304C\u5FC5\u9808\u3068\u306A\u308A\u307E\u3059\u3002</li>
|
|
4988
|
-
</ul>`,example:"normal",enum:["normal","discount","text"]},qty:{type:"number",minimum:0,maximum:99999999,description:"\u6570\u91CF",example:1},unit:{type:"string",description:"\u5358\u4F4D",example:"\u500B"},unit_price:{type:"number",minimum:-999999999999,maximum:999999999999,description:"\u5358\u4FA1 (tax_entry_method: inclusive\u306E\u5834\u5408\u306F\u7A0E\u8FBC\u4FA1\u683C\u3001tax_entry_method: exclusive\u306E\u5834\u5408\u306F\u7A0E\u629C\u4FA1\u683C\u3068\u306A\u308A\u307E\u3059)",example:1},vat:{type:"integer",format:"int64",nullable:!0,description:"\u6D88\u8CBB\u7A0E\u984D",example:8e3},description:{type:"string",description:"\u5099\u8003",example:"\u5099\u8003"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},tax_code:{type:"integer",format:"int64",minimum:0,maximum:2147483647,description:"\u7A0E\u533A\u5206\u30B3\u30FC\u30C9",example:1},item_id:{type:"integer",format:"int64",minimum:1,description:"\u54C1\u76EEID",example:1},section_id:{type:"integer",format:"int64",minimum:1,description:"\u90E8\u9580ID",example:1},tag_ids:{type:"array",items:{type:"integer",format:"int64",minimum:1,description:"\u30E1\u30E2\u30BF\u30B0ID",example:1}},segment_1_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF11\u30BF\u30B0ID",example:1},segment_2_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF12\u30BF\u30B0ID",example:1},segment_3_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF13\u30BF\u30B0ID",example:1}}}}}},fixedAssetResponse:{type:"object",required:["fixed_assets","fiscal_year","up_to_date","up_to_date_reasons"],properties:{fixed_assets:{type:"array",items:{type:"object",properties:{company_id:{type:"integer",format:"int64",minimum:1,description:"\u4E8B\u696D\u6240ID",example:1},id:{type:"integer",format:"int64",minimum:1,description:"\u56FA\u5B9A\u8CC7\u7523ID",example:1},name:{type:"string",description:"\u56FA\u5B9A\u8CC7\u7523\u540D",example:"pc"},management_number:{type:"string",nullable:!0,description:"\u7BA1\u7406\u756A\u53F7",example:"pc-0001"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:22},section_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u90E8\u9580ID",example:0},item_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u54C1\u76EEID",example:0},depreciation_method:{type:"string",description:"\u511F\u5374\u65B9\u6CD5:(\u5C11\u984D\u511F\u5374: small_sum_method, \u4E00\u62EC\u511F\u5374: lump_sum_method, \u5B9A\u984D\u6CD5: straight_line_method, \u5B9A\u7387\u6CD5: multiple_method, \u65E7\u5B9A\u7387\u6CD5: old_multiple_method, \u65E7\u5B9A\u984D\u6CD5: old_straight_line_method, \u511F\u5374\u306A\u3057: non_depreciate_method, \u4EFB\u610F\u511F\u5374: voluntary_method, \u5373\u6642\u511F\u5374: immediate_method, \u5747\u7B49\u511F\u5374: equal_method)",enum:["small_sum_method","lump_sum_method","straight_line_method","multiple_method","old_multiple_method","old_straight_line_method","non_depreciate_method","voluntary_method","immediate_method","equal_method"],example:"straight_line_method"},depreciation_account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u6E1B\u4FA1\u511F\u5374\u306B\u4F7F\u3046\u52D8\u5B9A\u79D1\u76EEID",example:99},prefecture_code:{type:"integer",format:"int64",minimum:-1,maximum:46,description:"\u90FD\u9053\u5E9C\u770C\u30B3\u30FC\u30C9\uFF08-1: \u8A2D\u5B9A\u3057\u306A\u3044\u30010:\u5317\u6D77\u9053\u30011:\u9752\u68EE\u30012:\u5CA9\u624B\u30013:\u5BAE\u57CE\u30014:\u79CB\u7530\u30015:\u5C71\u5F62\u30016:\u798F\u5CF6\u30017:\u8328\u57CE\u30018:\u6803\u6728\u30019:\u7FA4\u99AC\u300110:\u57FC\u7389\u300111:\u5343\u8449\u300112:\u6771\u4EAC\u300113:\u795E\u5948\u5DDD\u300114:\u65B0\u6F5F\u300115:\u5BCC\u5C71\u300116:\u77F3\u5DDD\u300117:\u798F\u4E95\u300118:\u5C71\u68A8\u300119:\u9577\u91CE\u300120:\u5C90\u961C\u300121:\u9759\u5CA1\u300122:\u611B\u77E5\u300123:\u4E09\u91CD\u300124:\u6ECB\u8CC0\u300125:\u4EAC\u90FD\u300126:\u5927\u962A\u300127:\u5175\u5EAB\u300128:\u5948\u826F\u300129:\u548C\u6B4C\u5C71\u300130:\u9CE5\u53D6\u300131:\u5CF6\u6839\u300132:\u5CA1\u5C71\u300133:\u5E83\u5CF6\u300134:\u5C71\u53E3\u300135:\u5FB3\u5CF6\u300136:\u9999\u5DDD\u300137:\u611B\u5A9B\u300138:\u9AD8\u77E5\u300139:\u798F\u5CA1\u300140:\u4F50\u8CC0\u300141:\u9577\u5D0E\u300142:\u718A\u672C\u300143:\u5927\u5206\u300144:\u5BAE\u5D0E\u300145:\u9E7F\u5150\u5CF6\u300146:\u6C96\u7E04",example:4,nullable:!0},city_name:{type:"string",nullable:!0,description:"\u7533\u544A\u5148\u5E02\u533A\u753A\u6751",example:"\u6E2F\u533A"},depreciation_amount:{type:"integer",format:"int64",description:"\u672C\u5E74\u5206\u306E\u511F\u5374\u8CBB\u5408\u8A08",example:"18533"},acquisition_cost:{type:"integer",format:"int64",description:"\u53D6\u5F97\u4FA1\u984D",example:"150000"},opening_balance:{type:"integer",format:"int64",description:"\u671F\u9996\u6B8B\u9AD8\uFF08\u53D6\u5F97\u65E5\u304C\u4F1A\u8A08\u671F\u9593\u306B\u542B\u307E\u308C\u308B\u3068\u304D\u671F\u9996\u6B8B\u9AD8\u306F0\u306B\u306A\u308A\u307E\u3059\u3002\uFF09",example:"92000"},undepreciated_balance:{type:"integer",format:"int64",description:"\u672A\u511F\u5374\u6B8B\u9AD8",example:"46000"},opening_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u9996\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"100000"},closing_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u672B\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"46000"},life_years:{type:"integer",format:"int64",description:"\u8010\u7528\u5E74\u6570",example:"5"},acquisition_date:{type:"string",description:"\u53D6\u5F97\u65E5",format:"date",example:"2021-07-13"},created_at:{type:"string",description:"\u4F5C\u6210\u65E5\u6642\uFF08ISO8601\u5F62\u5F0F\uFF09",example:"2021-07-15T18:30:24+09:00"},depreciation_status:{type:"string",description:"\u58F2\u5374\u3082\u3057\u304F\u306F\u9664\u5374\u30B9\u30C6\u30FC\u30BF\u30B9: (\u58F2\u5374\u6E08: sold, \u9664\u5374\u6E08: retired, \u511F\u5374\u6E08: depreciated, \u511F\u5374\u4E2D: depreciation, \u511F\u5374\u306A\u3057: non_depreciation)",enum:["sold","retired","depreciated","depreciation","non_depreciation"],example:"depreciation"},retire_date:{type:"string",format:"date",nullable:!0,description:"\u9664\u5374\u65E5\u3001\u3082\u3057\u304F\u306F\u58F2\u5374\u65E5",example:"2022-03-24"}}}},fiscal_year:{type:"object",required:["start_date","end_date"],properties:{start_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u958B\u59CB\u65E5 (yyyy-mm-dd)",example:"2022-01-01"},end_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u7D42\u4E86\u65E5 (yyyy-mm-dd)",example:"2022-12-31"}}},up_to_date:{type:"boolean",description:"\u96C6\u8A08\u7D50\u679C\u304C\u6700\u65B0\u304B\u3069\u3046\u304B",example:!0},up_to_date_reasons:{type:"array",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u5834\u5408\u306E\u8981\u56E0\u60C5\u5831",items:{type:"object",required:["code","message"],properties:{code:{type:"string",description:"\u30B3\u30FC\u30C9",example:"depreciation_creating",enum:["depreciation_creating","depreciation_create_error"]},message:{type:"string",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u7406\u7531",example:"\u5F53\u671F\u306E\u56FA\u5B9A\u8CC7\u7523\u306E\u511F\u5374\u4F5C\u6210\u304C\u5B8C\u4E86\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6B63\u3057\u3044\u96C6\u8A08\u7D50\u679C\u3067\u306A\u3044\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002"}}}}}},generalLedgersResponse:{type:"object",required:["general_ledgers"],properties:{general_ledgers:{type:"array",items:{type:"object",properties:{account_item_id:{type:"integer",format:"int64",description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},account_item_name:{type:"string",description:"\u52D8\u5B9A\u79D1\u76EE\u540D",example:"\u58F2\u639B\u91D1"},total_amount:{type:"integer",format:"int64",description:"\u767A\u751F\u984D\u7D2F\u8A08",example:100},final_balance:{type:"integer",format:"int64",description:"\u6B8B\u9AD8",example:100},debit_amount:{type:"integer",format:"int64",description:"\u501F\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100},credit_amount:{type:"integer",format:"int64",description:"\u8CB8\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100}}}}}},accountGroupCreateParams:{type:"object",required:["company_id","name","account_category_id"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",format:"int64",example:1},name:{type:"string",maxLength:20,description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D (20\u6587\u5B57\u4EE5\u5185)",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EA\u30FCID Selectables\u30D5\u30A9\u30FC\u30E0\u7528\u9078\u629E\u9805\u76EE\u60C5\u5831\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8(account_groups.account_category_id)\u3067\u53D6\u5F97\u53EF\u80FD\u3067\u3059",format:"int64",example:1},index:{type:"integer",description:"\u8868\u793A\u9806",format:"int64",example:1}}},accountGroupCreateResponse:{type:"object",required:["account_group"],properties:{account_group:{type:"object",required:["company_id","id","name","account_structure_id","account_category_id","index"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",example:1,format:"int64"},id:{type:"integer",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D(\u5C0F\u30AB\u30C6\u30B4\u30EA\u30FC)ID",example:1,format:"int64"},name:{type:"string",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_structure_id:{type:"integer",description:"\u5E74\u5EA6ID",example:1,format:"int64"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EAID",example:1,format:"int64"},index:{type:"integer",description:"\u8868\u793A\u9806",example:1,format:"int64"}}}}}},securitySchemes:{oauth2:{type:"oauth2",flows:{authorizationCode:{authorizationUrl:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenUrl:"https://accounts.secure.freee.co.jp/public_api/token",scopes:{write:"\u30C7\u30FC\u30BF\u306E\u66F8\u304D\u8FBC\u307F",read:"\u30C7\u30FC\u30BF\u306E\u8AAD\u307F\u53D6\u308A"}}}}}}};import{z as D}from"zod";function L(t){let{type:e}=t.schema||t,{description:n,required:i}=t,a;switch(e){case"string":a=D.string();break;case"integer":a=D.number().int();break;case"number":a=D.number();break;case"boolean":a=D.boolean();break;default:a=D.any()}return n&&(a=a.describe(n)),i||(a=a.optional()),a}function K(t){let e=t.replace(/^\/api\/\d+\//,"").replace(/\/{[^}]+}/g,"_by_id").replace(/\//g,"_");return e.length>50&&(e=e.substring(0,50)),e}function Q(t){let e=H.paths;Object.keys(e).sort().forEach(i=>{let a=e[i];Object.entries(a).forEach(([r,o])=>{let s=`${r}_${K(i)}`,c=o.summary||o.description||"",m={},d=o.parameters?.filter(l=>l.in==="path")||[];d.forEach(l=>{m[l.name]=L(l)});let x=o.parameters?.filter(l=>l.in==="query")||[];x.forEach(l=>{let u=L(l);l.name==="company_id"&&(u=u.optional()),m[l.name]=u});let j=ye.any();(r==="post"||r==="put")&&o.requestBody?.content?.["application/json"]?.schema&&(m.body=j.describe("Request body")),t.tool(s,c,m,async l=>{try{let u=i;d.forEach(b=>{u=u.replace(`{${b.name}}`,String(l[b.name]))});let z={};x.forEach(b=>{l[b.name]!==void 0&&(z[b.name]=l[b.name])});let ee=r==="post"||r==="put"?l.body:void 0,te=await w(r.toUpperCase(),u,z,ee);return{content:[{type:"text",text:JSON.stringify(te,null,2)}]}}catch(u){return{content:[{type:"text",text:`Error: ${u instanceof Error?u.message:String(u)}`}]}}})})})}async function X(){let t=new ge({name:p.server.name,version:p.server.version});Y(t),Q(t);try{await M(),console.error(`\u2705 OAuth callback server started on http://127.0.0.1:${p.oauth.callbackPort}`)}catch(n){console.error("\u26A0\uFE0F Failed to start callback server:",n),console.error("OAuth authentication will fall back to manual mode")}let e=new he;await t.connect(e),console.error("Freee MCP Server running on stdio"),process.on("SIGINT",()=>{P(),process.exit(0)}),process.on("SIGTERM",()=>{P(),process.exit(0)})}var fe=async()=>{await X()};fe().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|
|
4988
|
+
</ul>`,example:"normal",enum:["normal","discount","text"]},qty:{type:"number",minimum:0,maximum:99999999,description:"\u6570\u91CF",example:1},unit:{type:"string",description:"\u5358\u4F4D",example:"\u500B"},unit_price:{type:"number",minimum:-999999999999,maximum:999999999999,description:"\u5358\u4FA1 (tax_entry_method: inclusive\u306E\u5834\u5408\u306F\u7A0E\u8FBC\u4FA1\u683C\u3001tax_entry_method: exclusive\u306E\u5834\u5408\u306F\u7A0E\u629C\u4FA1\u683C\u3068\u306A\u308A\u307E\u3059)",example:1},vat:{type:"integer",format:"int64",nullable:!0,description:"\u6D88\u8CBB\u7A0E\u984D",example:8e3},description:{type:"string",description:"\u5099\u8003",example:"\u5099\u8003"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},tax_code:{type:"integer",format:"int64",minimum:0,maximum:2147483647,description:"\u7A0E\u533A\u5206\u30B3\u30FC\u30C9",example:1},item_id:{type:"integer",format:"int64",minimum:1,description:"\u54C1\u76EEID",example:1},section_id:{type:"integer",format:"int64",minimum:1,description:"\u90E8\u9580ID",example:1},tag_ids:{type:"array",items:{type:"integer",format:"int64",minimum:1,description:"\u30E1\u30E2\u30BF\u30B0ID",example:1}},segment_1_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF11\u30BF\u30B0ID",example:1},segment_2_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF12\u30BF\u30B0ID",example:1},segment_3_tag_id:{type:"integer",format:"int64",minimum:1,description:"\u30BB\u30B0\u30E1\u30F3\u30C8\uFF13\u30BF\u30B0ID",example:1}}}}}},fixedAssetResponse:{type:"object",required:["fixed_assets","fiscal_year","up_to_date","up_to_date_reasons"],properties:{fixed_assets:{type:"array",items:{type:"object",properties:{company_id:{type:"integer",format:"int64",minimum:1,description:"\u4E8B\u696D\u6240ID",example:1},id:{type:"integer",format:"int64",minimum:1,description:"\u56FA\u5B9A\u8CC7\u7523ID",example:1},name:{type:"string",description:"\u56FA\u5B9A\u8CC7\u7523\u540D",example:"pc"},management_number:{type:"string",nullable:!0,description:"\u7BA1\u7406\u756A\u53F7",example:"pc-0001"},account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u52D8\u5B9A\u79D1\u76EEID",example:22},section_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u90E8\u9580ID",example:0},item_id:{type:"integer",format:"int64",minimum:1,nullable:!0,description:"\u54C1\u76EEID",example:0},depreciation_method:{type:"string",description:"\u511F\u5374\u65B9\u6CD5:(\u5C11\u984D\u511F\u5374: small_sum_method, \u4E00\u62EC\u511F\u5374: lump_sum_method, \u5B9A\u984D\u6CD5: straight_line_method, \u5B9A\u7387\u6CD5: multiple_method, \u65E7\u5B9A\u7387\u6CD5: old_multiple_method, \u65E7\u5B9A\u984D\u6CD5: old_straight_line_method, \u511F\u5374\u306A\u3057: non_depreciate_method, \u4EFB\u610F\u511F\u5374: voluntary_method, \u5373\u6642\u511F\u5374: immediate_method, \u5747\u7B49\u511F\u5374: equal_method)",enum:["small_sum_method","lump_sum_method","straight_line_method","multiple_method","old_multiple_method","old_straight_line_method","non_depreciate_method","voluntary_method","immediate_method","equal_method"],example:"straight_line_method"},depreciation_account_item_id:{type:"integer",format:"int64",minimum:1,description:"\u6E1B\u4FA1\u511F\u5374\u306B\u4F7F\u3046\u52D8\u5B9A\u79D1\u76EEID",example:99},prefecture_code:{type:"integer",format:"int64",minimum:-1,maximum:46,description:"\u90FD\u9053\u5E9C\u770C\u30B3\u30FC\u30C9\uFF08-1: \u8A2D\u5B9A\u3057\u306A\u3044\u30010:\u5317\u6D77\u9053\u30011:\u9752\u68EE\u30012:\u5CA9\u624B\u30013:\u5BAE\u57CE\u30014:\u79CB\u7530\u30015:\u5C71\u5F62\u30016:\u798F\u5CF6\u30017:\u8328\u57CE\u30018:\u6803\u6728\u30019:\u7FA4\u99AC\u300110:\u57FC\u7389\u300111:\u5343\u8449\u300112:\u6771\u4EAC\u300113:\u795E\u5948\u5DDD\u300114:\u65B0\u6F5F\u300115:\u5BCC\u5C71\u300116:\u77F3\u5DDD\u300117:\u798F\u4E95\u300118:\u5C71\u68A8\u300119:\u9577\u91CE\u300120:\u5C90\u961C\u300121:\u9759\u5CA1\u300122:\u611B\u77E5\u300123:\u4E09\u91CD\u300124:\u6ECB\u8CC0\u300125:\u4EAC\u90FD\u300126:\u5927\u962A\u300127:\u5175\u5EAB\u300128:\u5948\u826F\u300129:\u548C\u6B4C\u5C71\u300130:\u9CE5\u53D6\u300131:\u5CF6\u6839\u300132:\u5CA1\u5C71\u300133:\u5E83\u5CF6\u300134:\u5C71\u53E3\u300135:\u5FB3\u5CF6\u300136:\u9999\u5DDD\u300137:\u611B\u5A9B\u300138:\u9AD8\u77E5\u300139:\u798F\u5CA1\u300140:\u4F50\u8CC0\u300141:\u9577\u5D0E\u300142:\u718A\u672C\u300143:\u5927\u5206\u300144:\u5BAE\u5D0E\u300145:\u9E7F\u5150\u5CF6\u300146:\u6C96\u7E04",example:4,nullable:!0},city_name:{type:"string",nullable:!0,description:"\u7533\u544A\u5148\u5E02\u533A\u753A\u6751",example:"\u6E2F\u533A"},depreciation_amount:{type:"integer",format:"int64",description:"\u672C\u5E74\u5206\u306E\u511F\u5374\u8CBB\u5408\u8A08",example:"18533"},acquisition_cost:{type:"integer",format:"int64",description:"\u53D6\u5F97\u4FA1\u984D",example:"150000"},opening_balance:{type:"integer",format:"int64",description:"\u671F\u9996\u6B8B\u9AD8\uFF08\u53D6\u5F97\u65E5\u304C\u4F1A\u8A08\u671F\u9593\u306B\u542B\u307E\u308C\u308B\u3068\u304D\u671F\u9996\u6B8B\u9AD8\u306F0\u306B\u306A\u308A\u307E\u3059\u3002\uFF09",example:"92000"},undepreciated_balance:{type:"integer",format:"int64",description:"\u672A\u511F\u5374\u6B8B\u9AD8",example:"46000"},opening_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u9996\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"100000"},closing_accumulated_depreciation:{type:"integer",format:"int64",description:"\u671F\u672B\u6E1B\u4FA1\u511F\u5374\u7D2F\u8A08\u984D",example:"46000"},life_years:{type:"integer",format:"int64",description:"\u8010\u7528\u5E74\u6570",example:"5"},acquisition_date:{type:"string",description:"\u53D6\u5F97\u65E5",format:"date",example:"2021-07-13"},created_at:{type:"string",description:"\u4F5C\u6210\u65E5\u6642\uFF08ISO8601\u5F62\u5F0F\uFF09",example:"2021-07-15T18:30:24+09:00"},depreciation_status:{type:"string",description:"\u58F2\u5374\u3082\u3057\u304F\u306F\u9664\u5374\u30B9\u30C6\u30FC\u30BF\u30B9: (\u58F2\u5374\u6E08: sold, \u9664\u5374\u6E08: retired, \u511F\u5374\u6E08: depreciated, \u511F\u5374\u4E2D: depreciation, \u511F\u5374\u306A\u3057: non_depreciation)",enum:["sold","retired","depreciated","depreciation","non_depreciation"],example:"depreciation"},retire_date:{type:"string",format:"date",nullable:!0,description:"\u9664\u5374\u65E5\u3001\u3082\u3057\u304F\u306F\u58F2\u5374\u65E5",example:"2022-03-24"}}}},fiscal_year:{type:"object",required:["start_date","end_date"],properties:{start_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u958B\u59CB\u65E5 (yyyy-mm-dd)",example:"2022-01-01"},end_date:{type:"string",description:"\u4F1A\u8A08\u5E74\u5EA6\u7D42\u4E86\u65E5 (yyyy-mm-dd)",example:"2022-12-31"}}},up_to_date:{type:"boolean",description:"\u96C6\u8A08\u7D50\u679C\u304C\u6700\u65B0\u304B\u3069\u3046\u304B",example:!0},up_to_date_reasons:{type:"array",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u5834\u5408\u306E\u8981\u56E0\u60C5\u5831",items:{type:"object",required:["code","message"],properties:{code:{type:"string",description:"\u30B3\u30FC\u30C9",example:"depreciation_creating",enum:["depreciation_creating","depreciation_create_error"]},message:{type:"string",description:"\u96C6\u8A08\u304C\u6700\u65B0\u3067\u306A\u3044\u7406\u7531",example:"\u5F53\u671F\u306E\u56FA\u5B9A\u8CC7\u7523\u306E\u511F\u5374\u4F5C\u6210\u304C\u5B8C\u4E86\u3057\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6B63\u3057\u3044\u96C6\u8A08\u7D50\u679C\u3067\u306A\u3044\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002"}}}}}},generalLedgersResponse:{type:"object",required:["general_ledgers"],properties:{general_ledgers:{type:"array",items:{type:"object",properties:{account_item_id:{type:"integer",format:"int64",description:"\u52D8\u5B9A\u79D1\u76EEID",example:1},account_item_name:{type:"string",description:"\u52D8\u5B9A\u79D1\u76EE\u540D",example:"\u58F2\u639B\u91D1"},total_amount:{type:"integer",format:"int64",description:"\u767A\u751F\u984D\u7D2F\u8A08",example:100},final_balance:{type:"integer",format:"int64",description:"\u6B8B\u9AD8",example:100},debit_amount:{type:"integer",format:"int64",description:"\u501F\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100},credit_amount:{type:"integer",format:"int64",description:"\u8CB8\u65B9\u767A\u751F\u984D\u7D2F\u8A08",example:100}}}}}},accountGroupCreateParams:{type:"object",required:["company_id","name","account_category_id"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",format:"int64",example:1},name:{type:"string",maxLength:20,description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D (20\u6587\u5B57\u4EE5\u5185)",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EA\u30FCID Selectables\u30D5\u30A9\u30FC\u30E0\u7528\u9078\u629E\u9805\u76EE\u60C5\u5831\u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8(account_groups.account_category_id)\u3067\u53D6\u5F97\u53EF\u80FD\u3067\u3059",format:"int64",example:1},index:{type:"integer",description:"\u8868\u793A\u9806",format:"int64",example:1}}},accountGroupCreateResponse:{type:"object",required:["account_group"],properties:{account_group:{type:"object",required:["company_id","id","name","account_structure_id","account_category_id","index"],properties:{company_id:{type:"integer",description:"\u4E8B\u696D\u6240ID",example:1,format:"int64"},id:{type:"integer",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D(\u5C0F\u30AB\u30C6\u30B4\u30EA\u30FC)ID",example:1,format:"int64"},name:{type:"string",description:"\u6C7A\u7B97\u66F8\u8868\u793A\u540D",example:"\u65B0\u3057\u3044\u6C7A\u7B97\u66F8\u8868\u793A\u540D"},account_structure_id:{type:"integer",description:"\u5E74\u5EA6ID",example:1,format:"int64"},account_category_id:{type:"integer",description:"\u52D8\u5B9A\u79D1\u76EE\u30AB\u30C6\u30B4\u30EAID",example:1,format:"int64"},index:{type:"integer",description:"\u8868\u793A\u9806",example:1,format:"int64"}}}}}},securitySchemes:{oauth2:{type:"oauth2",flows:{authorizationCode:{authorizationUrl:"https://accounts.secure.freee.co.jp/public_api/authorize",tokenUrl:"https://accounts.secure.freee.co.jp/public_api/token",scopes:{write:"\u30C7\u30FC\u30BF\u306E\u66F8\u304D\u8FBC\u307F",read:"\u30C7\u30FC\u30BF\u306E\u8AAD\u307F\u53D6\u308A"}}}}}}};import{z as D}from"zod";function N(t){let{type:e}=t.schema||t,{description:n,required:i}=t,a;switch(e){case"string":a=D.string();break;case"integer":a=D.number().int();break;case"number":a=D.number();break;case"boolean":a=D.boolean();break;default:a=D.any()}return n&&(a=a.describe(n)),i||(a=a.optional()),a}function X(t){let e=t.replace(/^\/api\/\d+\//,"").replace(/\/{[^}]+}/g,"_by_id").replace(/\//g,"_");return e.length>50&&(e=e.substring(0,50)),e}function ee(t){let e=Q.paths;Object.keys(e).sort().forEach(i=>{let a=e[i];Object.entries(a).forEach(([r,o])=>{let s=`${r}_${X(i)}`,c=o.summary||o.description||"",m={},d=o.parameters?.filter(l=>l.in==="path")||[];d.forEach(l=>{m[l.name]=N(l)});let x=o.parameters?.filter(l=>l.in==="query")||[];x.forEach(l=>{let u=N(l);l.name==="company_id"&&(u=u.optional()),m[l.name]=u});let j=fe.any();(r==="post"||r==="put")&&o.requestBody?.content?.["application/json"]?.schema&&(m.body=j.describe("Request body")),t.tool(s,c,m,async l=>{try{let u=i;d.forEach(b=>{u=u.replace(`{${b.name}}`,String(l[b.name]))});let F={};x.forEach(b=>{l[b.name]!==void 0&&(F[b.name]=l[b.name])});let ne=r==="post"||r==="put"?l.body:void 0,ie=await w(r.toUpperCase(),u,F,ne);return{content:[{type:"text",text:JSON.stringify(ie,null,2)}]}}catch(u){return{content:[{type:"text",text:`Error: ${u instanceof Error?u.message:String(u)}`}]}}})})})}async function te(){let t=new xe({name:p.server.name,version:p.server.version});K(t),ee(t);try{await V(),console.error(`\u2705 OAuth callback server started on http://127.0.0.1:${p.oauth.callbackPort}`)}catch(n){console.error("\u26A0\uFE0F Failed to start callback server:",n),console.error("OAuth authentication will fall back to manual mode")}let e=new be;await t.connect(e),console.error("Freee MCP Server running on stdio"),process.on("SIGINT",()=>{T(),process.exit(0)}),process.on("SIGTERM",()=>{T(),process.exit(0)})}var qe=async()=>{await te()};qe().catch(t=>{console.error("Fatal error:",t),process.exit(1)});
|