Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@ A [MCP(Model Context Protocol)](https://www.anthropic.com/news/model-context-pro

Available tools:

### Japan Market

- `buffett_code_get_jp_company` - Get Japanese company information from Buffett Code
- `buffett_code_get_jp_company_daily` - Get daily Japanese company information from Buffett Code for a specific date
- `buffett_code_get_jp_company_quarterly` - Get quarterly Japanese company information from Buffett Code for a specific year and quarter
- `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.
- `buffett_code_get_jp_company_weekly_stats` - Get weekly statistics calculated for the company or stock, mainly including stock price related statistics.
- `buffett_code_get_jp_company_monthly_stats` - Get monthly statistics calculated for the company or stock, mainly including stock price related statistics.
- `buffett_code_get_jp_company_monthly_kpis` - Get monthly KPIs for a JP company.
- `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.
- `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.
- `buffett_code_get_jp_company_quarterly_segments` - Get segment information as disclosed in a company or stock’s securities report or quarterly report.
- `buffett_code_get_jp_company_annually_guidance_revisions` - Get a list of earnings guidance revisions by fiscal year for the company or stock.
- `buffett_code_get_jp_company_similarities` - Get a list of companies similar to the specified company.

### US Market

- `buffett_code_get_us_company` - Get company information from Buffett Code
- `buffett_code_get_us_company_daily` - Get daily company information from Buffett Code for a specific date
- `buffett_code_get_us_company_quarterly` - Get quarterly company information from Buffett Code for a specific year and quarter
- `buffett_code_get_us_company_stocks` - Get company stock information from Buffett Code for a specific stock
- `buffett_code_get_us_company_stocks_daily` Get daily company stock information from Buffett Code for a specific stock and date
- `buffett_code_get_us_company_stocks_daily` - Get daily company stock information from Buffett Code for a specific stock and date
- `buffett_code_get_us_company_stocks_quarterly` - Get quarterly company stock information from Buffett Code for a specific stock and year-quarter

## Quick Start
Expand Down
85 changes: 85 additions & 0 deletions examples/get_jp_company.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { config } from 'dotenv';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { CallToolResult, CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';

// Get the current file's directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Load environment variables from .env file
config();

// Get and validate required environment variables
const apiKey = process.env.BUFFETT_CODE_API_KEY;
if (!apiKey) {
throw new Error(
'BUFFETT_CODE_API_KEY environment variable is required. Set it in your .env file.'
);
}

// Compose env for child process
const env = {
BUFFETT_CODE_API_KEY: apiKey,
} as const satisfies Record<string, string>;

async function main() {
// Initialize MCP client
const client = new Client(
{
name: 'buffett-code-mcp-example-client',
version: '1.0.0',
},
{
capabilities: {},
}
);

// Create transport to connect to the server
const transport = new StdioClientTransport({
command: process.execPath,
args: [
resolve(__dirname, '../dist/index.js'), // pre-build server
],
env,
});

try {
// Connect to the server
await client.connect(transport);
console.log('Connected to BuffetCode MCP server');

const response = (await client.callTool(
{
name: 'buffett_code_get_jp_company',
arguments: {
companyId: '9101', // 日本郵船
},
},
CallToolResultSchema
)) as CallToolResult;

if (
Array.isArray(response.content) &&
response.content[0]?.type === 'text'
) {
const data = JSON.parse(response.content[0].text);
console.log('Company data (example):', data);
} else {
console.error('Unexpected response format for example call');
}
} catch (error) {
console.error('Error:', error);
process.exit(1);
} finally {
await transport.close();
console.log('Connection closed.');
}
}

main().catch((error) => {
console.error('Fatal error in main:', error);
process.exit(1);
});
8 changes: 0 additions & 8 deletions examples/get_us_company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ async function main() {
await client.connect(transport);
console.log('Connected to BuffetCode MCP server');

// List available tools
const toolsResponse = await client.listTools();

console.log('Available tools:');
toolsResponse.tools.forEach(tool => {
console.log(`- ${tool.name}: ${tool.description}`);
});

const response = (await client.callTool(
{
name: 'buffett_code_get_us_company',
Expand Down
72 changes: 72 additions & 0 deletions examples/list_tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { config } from 'dotenv';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';

// Get the current file's directory
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// Load environment variables from .env file
config();

// Get and validate required environment variables
const apiKey = process.env.BUFFETT_CODE_API_KEY;
if (!apiKey) {
throw new Error(
'BUFFETT_CODE_API_KEY environment variable is required. Set it in your .env file.'
);
}

// Compose env for child process
const env = {
BUFFETT_CODE_API_KEY: apiKey,
} as const satisfies Record<string, string>;

async function main() {
// Initialize MCP client
const client = new Client(
{
name: 'buffett-code-mcp-example-client',
version: '1.0.0',
},
{
capabilities: {},
}
);

// Create transport to connect to the server
const transport = new StdioClientTransport({
command: process.execPath,
args: [
resolve(__dirname, '../dist/index.js'), // pre-build server
],
env,
});

try {
// Connect to the server
await client.connect(transport);
console.log('Connected to BuffetCode MCP server');

// List available tools
const toolsResponse = await client.listTools();

console.log('Available tools:');
toolsResponse.tools.forEach(tool => {
console.log(`- ${tool.name}: ${tool.description}`);
});
} catch (error) {
console.error('Error:', error);
process.exit(1);
} finally {
await transport.close();
console.log('Connection closed.');
}
}

main().catch((error) => {
console.error('Fatal error in main:', error);
process.exit(1);
});
Loading