eviews-mcp
eviews-mcp
通过 Python 驱动 EViews,并通过模型上下文协议(Model Context Protocol)将其暴露给 LLM 客户端。
一个包包含两样东西:
一个库。 用于脚本和笔记本的
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")非数值列会被跳过,而不是导致整个数据框失败。
图形
图形无法以文本形式呈现,因此将其写入文件:
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。
值得了解的行为
以下是库为你处理的 EViews 特性,之所以记录是因为它们会让直接编写 COM 代码的人感到意外。
写入遵循活动样本。 在
smpl 2000m3 2000m6下,写入 12 个值只会落 4 个,其余静默保持 NA。因此写入默认针对整个页面;传递sample=""可选择使用当前样本。save忽略文件扩展名。graph.save "out.png"写入的是 EMF 数据。格式是显式传递的,如果保存未产生文件,会引发异常而不是报告成功。相对路径相对于 EViews 解析,而不是调用进程,因此路径在传递前会被转换为绝对路径。
带日期的数据框决定页面。 将 12 行的季度数据框写入打开的 80 行页面会把值放在错误的日期上,因此会创建一个与数据框匹配的页面。
无日志重定向。
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 # 58 tests, drives the library APIpytest 默认运行离线套件;实时套件为可选,因为它们需要 EViews 许可证。
许可证
MIT。版权所有 (c) 2026 Merwan Roudane。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityAmaintenanceAn MCP server that lets Large Language Models interact with Stata software to perform regression analysis and other statistical operations.4243AGPL 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.10MIT
- AlicenseAqualityBmaintenanceDeterministic 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
Related MCP Connectors
MCP server exposing the Backtest360 engine API as tools for AI agents.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/merwanroudane/MCP_EVIEWS'
If you have feedback or need assistance with the MCP directory API, please join our Discord server