eviews-mcp
eviews-mcp
从 Python 驱动 EViews,并通过 Model Context Protocol 将其暴露给 LLM 客户端。
一个包包含两样东西:
一个库。 用于脚本和 notebook 的
EViews类——创建工作文件、估计模型、以文本或 pandas DataFrame 形式读回结果。一个 MCP 服务器。 将同样的能力以工具形式提供,使助手能够在真实的 EViews 会话中做计量经济学分析。
在 Windows 上针对 EViews 13 构建和测试;EViews 10–14 可通过相同的 COM 接口正确解析。
刚接触这个? EViews 研究者指南 带你从一台干净机器到完成一项 ARDL 研究,每一条命令和每一份输出都经过真实 EViews 会话验证。无需任何 Python 知识。
安装
pip install eviews-mcp带 pandas 支持:
pip install "eviews-mcp[pandas]"或者从克隆的仓库安装,用于开发:
git clone https://github.com/merwanroudane/MCP_EVIEWS.git
cd MCP_EVIEWS
pip install -e .[dev]需要 Windows 和本地 EViews 安装,因为它通过 COM 自动化驱动 EViews。
Related MCP server: econstats-mcp
库的使用
from eviews_mcp import EViews
with EViews() as ev:
ev.create_workfile("q", "1990q1", "2020q4")
ev.run("""
series k = 100 + @trend + 3*@nrnd
series l = 50 + 0.5*@trend + 2*@nrnd
series gdp = 10 + 0.6*k + 0.3*l + 2*@nrnd
equation eq1.ls gdp c k l
""")
print(ev.show("eq1"))
print(ev.value("eq1.@r2"))Dependent Variable: GDP
Method: Least Squares
Included observations: 124
Variable Coefficient Std. Error t-Statistic Prob.
C 9.58073 0.829252 11.5535 2.90e-21
K 0.591693 0.0333819 17.7250 1.99e-35
L 0.322394 0.0673315 4.78816 4.81e-06
R-squared 0.994702 Mean dependent var 131.080任意 EViews 视图,以文本形式
show 接受一个视图,因此诊断不需要额外的 API:
ev.show("eq1", "wald c(2)=c(3)") # coefficient restriction test
ev.show("eq1", "resids(t)") # residual table
ev.show("eq1", "coefcov") # coefficient covariance
ev.show("eq1", "auto(2)") # Breusch-Godfrey serial correlation
ev.show("eq1", "white") # White heteroskedasticity test
ev.show("gdp", "uroot") # unit root test
ev.show("gdp", "correl") # correlogram
ev.show("ardl1", "cointrel") # ARDL long-run relationship
ev.show("var1", "impulse(t)") # impulse response table
ev.show("var1", "testexog") # Granger causalityresids 和 impulse 默认绘制图形;(t) 变体要求 EViews 提供表格形式。冻结为 spool 而非表格的视图——其中包括 ARDL 协整关系——完全无法通过 COM 读取,因此 show 对这类视图回退为文本转储。
如果需要数字而不是布局,table() 以完整双精度返回原始行,value() 返回一个数字:
rows = ev.table("eq1") # tuple of row tuples
r2 = ev.value("eq1.@r2") # 0.9947015...
beta = ev.value("eq1.@coefs(2)")结果是数据,不只是文本
show 将表格格式化为便于阅读的形式。以下这些则返回数字本身,用于测试、制表或传递给其他工具:
ev.coefficients("eq1")
# [{'variable': 'LNK', 'coefficient': 0.549198724914677,
# 'std_error': 0.023936158605687322, 't_stat': 22.94431341143375,
# 'p_value': 5.677925593821611e-41}, ...]
ev.fit("eq1")["R-squared"] # 0.9858630667863459整合阶数,逐次差分检验直到平稳:
ev.unit_root("lngdp")
# {'series': 'LNGDP', 'order_of_integration': 1, 'conclusion': 'I(1)',
# 'steps': [{'difference': 0, 'statistic': -0.5001, 'p_value': 0.8856, ...},
# {'difference': 1, 'statistic': -12.1778, 'p_value': 0.0001, ...}]}传入 options 以选择检验:"pp" 表示 Phillips-Perron,"kpss" 表示 KPSS,"adf, trend" 表示加入趋势项。KPSS 颠倒了原假设,因此报告的阶数不适用于它。
一次调用完成标准的事后估计检验组合:
report = ev.diagnose("eq1")
report["summary"]
# 'All 3 diagnostics pass at the 0.05 level.'Breusch-Godfrey、White 和 Jarque-Bera,各自带有统计量、p 值以及是否拒绝原假设。无法运行的检验会列在 report["skipped"] 下,并附上 EViews 给出的原因,因此摘要永远不会高估实际检查了多少内容。
这些结论是针对你选择的显著性水平读取 p 值。它们并不能证明一个设定是可靠的——结构突变、季节性和短样本都会误导这些检验。
pandas 双向转换
frame = ev.to_dataframe(["gdp", "k", "l"]) # indexed 1990Q1, 1990Q2, ...
frame.corr()写回时,DatetimeIndex 或 PeriodIndex 决定页面频率和跨度,因此日期保持对齐:
import numpy as np
import pandas as pd
rng = np.random.default_rng(7)
index = pd.period_range("2005Q1", periods=40, freq="Q")
unemployment = 7.0 - 0.05 * np.arange(40) + rng.normal(0, 0.4, 40)
df = pd.DataFrame(
{"unemployment": unemployment,
"inflation": 9.0 - 0.9 * unemployment + rng.normal(0, 0.5, 40)},
index=index,
)
ev.from_dataframe(df) # creates a quarterly 2005Q1-2014Q4 page
ev.run("equation phillips.ls inflation c unemployment")非数值列会被跳过,而不会导致整个 DataFrame 失败。
图形
图形无法以文本形式渲染,因此将其写入文件:
ev.export_object("phillips", "residuals.png", view="resids")图形格式:png、jpg、pdf、emf、wmf、bmp、gif、eps、tex。表格格式:csv、rtf、txt、html。
错误
EViews 会精确报告失败原因,包括程序内部的行号,这些消息会原样传递:
ev.run("""series ok = 1
broken_command
""")EViewsError: BROKEN_COMMAND is not defined or is an illegal command in "BROKEN_COMMAND"
in MCP_77B699157F3B.PRG on line 2.生成的程序每次运行都会使用随机名称,因此只有该部分会变化。
MCP 服务器的使用
向你的 MCP 客户端注册 eviews-mcp 命令:
{
"mcpServers": {
"eviews": {
"command": "eviews-mcp"
}
}
}对于 Claude Code:
claude mcp add eviews -- eviews-mcp工具
工具 | 用途 |
| 连接、版本、活动工作文件。调试时从这里开始。 |
| 丢弃当前实例并重新开始。 |
| 显示或隐藏 EViews 窗口。 |
| 按频率和范围新建页面。 |
| 打开和保存 |
| 关闭一个或所有打开的工作文件。 |
| 名称、页面、频率、范围、样本。 |
| 对象清单,可按 EViews 类型过滤。 |
| 设置估计样本。 |
| 主要工具。 运行一段 EViews 程序代码。 |
| 运行现有的 |
| 单条命令行。 |
| 将任意对象渲染为文本表格。 |
| 从表达式中取一个值。 |
| 类型,以及序列的统计量。 |
| 系数,以干净的数值表格呈现。 |
| 整合阶数,逐次差分检验。 |
| 序列相关、异方差和正态性。 |
| 序列,以对齐表格或全精度 CSV 形式。 |
| 将值写入序列。 |
| 读取 |
| 将序列写入文件。 |
| 保存对象——这是获取图形的方式。 |
run_eviews_code 不会回显结果,因为 EViews 将程序输出发送到自己的日志窗口,COM 无法访问该窗口。请将结果估计到命名对象中,然后对其调用 show。
故障排除
如果服务器无法启动
1.3.3 之前的版本可能安装 MCP SDK 2.x,该版本移除了此服务器所依赖的模块。症状每次都一样:
ModuleNotFoundError: No module named 'mcp.server.fastmcp'1.3.3 将 SDK 锁定在 2.0 以下。升级即可修复——但 pip 可能提供发布之前缓存的索引,因此请绕过缓存:
pip install --upgrade --no-cache-dir "eviews-mcp[pandas]"确认服务器本身可以导入,而不仅仅是包。该包是惰性导入的,即使 SDK 不可用也会成功,因此检查它不能证明任何问题:
python -c "import eviews_mcp.server as s; print(len(s.mcp._tool_manager.list_tools()), 'tools')"二十四个工具意味着安装是健康的。
值得了解的行为
这些是 EViews 的特性,库会为你处理,之所以记录在这里,是因为它们会让直接编写 COM 代码的人感到意外。
写入操作遵循活动样本。 在
smpl 2000m3 2000m6下,写入 12 个值只会落 4 个,其余静默保持 NA。因此写入默认针对整个页面;传入sample=""可选择使用当前样本。save忽略文件扩展名。graph.save "out.png"写入的是 EMF 数据。格式是显式传递的,未产生文件的保存会抛出异常而不是报告成功。相对路径相对于 EViews 解析,而不是调用进程,因此路径在传递之前会被转换为绝对路径。
带日期的 DataFrame 决定页面。 将 12 行的季度 DataFrame 写入一个已打开的 80 行页面会把值落在错误的日期上,因此会改为创建与 DataFrame 匹配的页面。
无日志重定向。
output命令需要冻结对象名称,否则什么都不写,因此它无法捕获日志。结果来自将对象冻结为表格并读取该表格。无
GetScalar/PutScalar/GetString。 这些在 EViews COM 接口上根本不存在。Get涵盖它们并推断类型。单 COM 线程。 MCP 在线程池中分派同步工具,而 COM 指针在跨单元时无效,因此每次 EViews 调用都被汇集到单个初始化了单元的线程上。
导入到已打开的工作文件会将文件截断为该页面的长度,而且是静默的。因此导入默认创建新工作文件;合并到当前页面是选择加入的。
EViews 限制可同时打开的工作文件数量,超出后拒绝创建新的,因此
close_workfile的存在是为了保持长时间会话的健康。
测试
python tests/test_offline.py # 27 tests, no EViews needed
python tests/test_live.py # 25 tests, drives the MCP tool layer
python tests/test_live_client.py # 62 tests, drives the library APIpytest 默认运行离线套件;在线套件是选择加入的,因为它们需要 EViews 许可证。
许可证
MIT。版权所有 (c) 2026 Merwan Roudane。
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
MCP server exposing the Backtest360 engine API as tools for AI agents.
MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Related MCP Servers
- AlicenseAqualityAmaintenanceAn MCP server that lets Large Language Models interact with Stata software to perform regression analysis and other statistical operations.43,836 PyPI266AGPL 3.0
- FlicenseNot gradedqualityDmaintenanceEconomic data MCP server that connects FRED, BLS, BEA, IMF, World Bank, and ECB to any MCP-compatible client, with built-in methodology rules to guide LLMs in selecting appropriate economic indicators.-
- AlicenseNot gradedqualityDmaintenanceEconometrics MCP server for regression, causal inference, time series, panel data, machine learning, and broader statistical analysis workflows.73 PyPI10MIT
- AlicenseAqualityDmaintenanceDeterministic time-series statistics for AI agents. This MCP server gives any LLM agent unit-tested statistical tools — anomaly detection, changepoint detection, seasonal decomposition, stationarity/trend tests, data-quality audits, baseline forecasts — with schema-validated structured output and no arbitrary code execution.17MIT