修改数据获取方式
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
require('dotenv').config()
|
||||
const axios = require('axios')
|
||||
|
||||
async function call(tool, query) {
|
||||
const base = process.env.EASTMONEY_MCP_BASE || 'https://mxapi.eastmoney.com/mxds/mcp'
|
||||
const payload = {
|
||||
jsonrpc: '2.0', id: 1, method: 'tools/call',
|
||||
params: { name: tool, arguments: { query } },
|
||||
}
|
||||
const resp = await axios.post(base, payload, {
|
||||
timeout: 60000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json, text/event-stream',
|
||||
'em_api_key': process.env.EM_API_KEY,
|
||||
},
|
||||
validateStatus: () => true,
|
||||
responseType: 'text',
|
||||
transformResponse: [(d) => d],
|
||||
})
|
||||
const body = String(resp.data)
|
||||
try {
|
||||
const j = JSON.parse(body)
|
||||
const text = j.result.content[0].text
|
||||
const parsed = JSON.parse(text)
|
||||
console.log(`\n=== ${tool}: "${query}" ===`)
|
||||
console.log('sheets 数量:', parsed.data.length)
|
||||
parsed.data.forEach((s, i) => {
|
||||
console.log(`\nsheet[${i}]:`)
|
||||
console.log(' sheetName:', s.sheetName)
|
||||
console.log(' columns[0..3]:', s.columns.slice(0, 4))
|
||||
console.log(' items[0][0..3]:', s.items[0] ? s.items[0].slice(0, 4) : '(无)')
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('解析失败:', e.message)
|
||||
console.log(body.slice(0, 1000))
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await call('mx_macro_data', '查询中国 2020-2025 年 CPI 月度同比数据')
|
||||
await call('mx_macro_data', '查询中国 2015-2024 年 GDP 同比增速年度数据')
|
||||
}
|
||||
main().catch(console.error)
|
||||
Reference in New Issue
Block a user