Skip to content

Commit f800394

Browse files
authored
Merge pull request #3 from BuffettCode/syucream/other-tools
Add tools to call JP company specific APIs
2 parents c76cd39 + 21d7041 commit f800394

8 files changed

Lines changed: 893 additions & 33 deletions

File tree

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,28 @@ A [MCP(Model Context Protocol)](https://www.anthropic.com/news/model-context-pro
66

77
Available tools:
88

9+
### Japan Market
10+
11+
- `buffett_code_get_jp_company` - Get Japanese company information from Buffett Code
12+
- `buffett_code_get_jp_company_daily` - Get daily Japanese company information from Buffett Code for a specific date
13+
- `buffett_code_get_jp_company_quarterly` - Get quarterly Japanese company information from Buffett Code for a specific year and quarter
14+
- `buffett_code_get_jp_company_daily_market_reaction` - Get the daily market reaction for a JP company as both text and stock price change rate. Currently available only for stocks with sufficient data, on or near quarterly or annual earnings announcement dates.
15+
- `buffett_code_get_jp_company_weekly_stats` - Get weekly statistics calculated for the company or stock, mainly including stock price related statistics.
16+
- `buffett_code_get_jp_company_monthly_stats` - Get monthly statistics calculated for the company or stock, mainly including stock price related statistics.
17+
- `buffett_code_get_jp_company_monthly_kpis` - Get monthly KPIs for a JP company.
18+
- `buffett_code_get_jp_company_quarterly_long_text_content` - Get processed long-form text content from Buffett Code, based on HTML text found in securities reports or quarterly reports.
19+
- `buffett_code_get_jp_company_quarterly_major_shareholders` - Get major shareholders information for a company or stock as listed in its securities report or quarterly report.
20+
- `buffett_code_get_jp_company_quarterly_segments` - Get segment information as disclosed in a company or stock’s securities report or quarterly report.
21+
- `buffett_code_get_jp_company_annually_guidance_revisions` - Get a list of earnings guidance revisions by fiscal year for the company or stock.
22+
- `buffett_code_get_jp_company_similarities` - Get a list of companies similar to the specified company.
23+
24+
### US Market
25+
926
- `buffett_code_get_us_company` - Get company information from Buffett Code
1027
- `buffett_code_get_us_company_daily` - Get daily company information from Buffett Code for a specific date
1128
- `buffett_code_get_us_company_quarterly` - Get quarterly company information from Buffett Code for a specific year and quarter
1229
- `buffett_code_get_us_company_stocks` - Get company stock information from Buffett Code for a specific stock
13-
- `buffett_code_get_us_company_stocks_daily` Get daily company stock information from Buffett Code for a specific stock and date
30+
- `buffett_code_get_us_company_stocks_daily` - Get daily company stock information from Buffett Code for a specific stock and date
1431
- `buffett_code_get_us_company_stocks_quarterly` - Get quarterly company stock information from Buffett Code for a specific stock and year-quarter
1532

1633
## Quick Start

examples/get_jp_company.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
3+
import { config } from 'dotenv';
4+
import { fileURLToPath } from 'node:url';
5+
import { dirname, resolve } from 'node:path';
6+
import { CallToolResult, CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
7+
8+
// Get the current file's directory
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
// Load environment variables from .env file
13+
config();
14+
15+
// Get and validate required environment variables
16+
const apiKey = process.env.BUFFETT_CODE_API_KEY;
17+
if (!apiKey) {
18+
throw new Error(
19+
'BUFFETT_CODE_API_KEY environment variable is required. Set it in your .env file.'
20+
);
21+
}
22+
23+
// Compose env for child process
24+
const env = {
25+
BUFFETT_CODE_API_KEY: apiKey,
26+
} as const satisfies Record<string, string>;
27+
28+
async function main() {
29+
// Initialize MCP client
30+
const client = new Client(
31+
{
32+
name: 'buffett-code-mcp-example-client',
33+
version: '1.0.0',
34+
},
35+
{
36+
capabilities: {},
37+
}
38+
);
39+
40+
// Create transport to connect to the server
41+
const transport = new StdioClientTransport({
42+
command: process.execPath,
43+
args: [
44+
resolve(__dirname, '../dist/index.js'), // pre-build server
45+
],
46+
env,
47+
});
48+
49+
try {
50+
// Connect to the server
51+
await client.connect(transport);
52+
console.log('Connected to BuffetCode MCP server');
53+
54+
const response = (await client.callTool(
55+
{
56+
name: 'buffett_code_get_jp_company',
57+
arguments: {
58+
companyId: '9101', // 日本郵船
59+
},
60+
},
61+
CallToolResultSchema
62+
)) as CallToolResult;
63+
64+
if (
65+
Array.isArray(response.content) &&
66+
response.content[0]?.type === 'text'
67+
) {
68+
const data = JSON.parse(response.content[0].text);
69+
console.log('Company data (example):', data);
70+
} else {
71+
console.error('Unexpected response format for example call');
72+
}
73+
} catch (error) {
74+
console.error('Error:', error);
75+
process.exit(1);
76+
} finally {
77+
await transport.close();
78+
console.log('Connection closed.');
79+
}
80+
}
81+
82+
main().catch((error) => {
83+
console.error('Fatal error in main:', error);
84+
process.exit(1);
85+
});

examples/get_us_company.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ async function main() {
5151
await client.connect(transport);
5252
console.log('Connected to BuffetCode MCP server');
5353

54-
// List available tools
55-
const toolsResponse = await client.listTools();
56-
57-
console.log('Available tools:');
58-
toolsResponse.tools.forEach(tool => {
59-
console.log(`- ${tool.name}: ${tool.description}`);
60-
});
61-
6254
const response = (await client.callTool(
6355
{
6456
name: 'buffett_code_get_us_company',

examples/list_tools.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
3+
import { config } from 'dotenv';
4+
import { fileURLToPath } from 'node:url';
5+
import { dirname, resolve } from 'node:path';
6+
7+
// Get the current file's directory
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = dirname(__filename);
10+
11+
// Load environment variables from .env file
12+
config();
13+
14+
// Get and validate required environment variables
15+
const apiKey = process.env.BUFFETT_CODE_API_KEY;
16+
if (!apiKey) {
17+
throw new Error(
18+
'BUFFETT_CODE_API_KEY environment variable is required. Set it in your .env file.'
19+
);
20+
}
21+
22+
// Compose env for child process
23+
const env = {
24+
BUFFETT_CODE_API_KEY: apiKey,
25+
} as const satisfies Record<string, string>;
26+
27+
async function main() {
28+
// Initialize MCP client
29+
const client = new Client(
30+
{
31+
name: 'buffett-code-mcp-example-client',
32+
version: '1.0.0',
33+
},
34+
{
35+
capabilities: {},
36+
}
37+
);
38+
39+
// Create transport to connect to the server
40+
const transport = new StdioClientTransport({
41+
command: process.execPath,
42+
args: [
43+
resolve(__dirname, '../dist/index.js'), // pre-build server
44+
],
45+
env,
46+
});
47+
48+
try {
49+
// Connect to the server
50+
await client.connect(transport);
51+
console.log('Connected to BuffetCode MCP server');
52+
53+
// List available tools
54+
const toolsResponse = await client.listTools();
55+
56+
console.log('Available tools:');
57+
toolsResponse.tools.forEach(tool => {
58+
console.log(`- ${tool.name}: ${tool.description}`);
59+
});
60+
} catch (error) {
61+
console.error('Error:', error);
62+
process.exit(1);
63+
} finally {
64+
await transport.close();
65+
console.log('Connection closed.');
66+
}
67+
}
68+
69+
main().catch((error) => {
70+
console.error('Fatal error in main:', error);
71+
process.exit(1);
72+
});

0 commit comments

Comments
 (0)