Skip to main content
Glama

内存缓存服务器

铁匠徽章

模型上下文协议 (MCP) 服务器,通过在语言模型交互之间高效缓存数据来减少令牌消耗。可与任何 MCP 客户端和任何使用令牌的语言模型兼容。

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装内存缓存服务器:

npx -y @smithery/cli install @tosin2013/mcp-memory-cache-server --client claude

手动安装

  1. 克隆存储库:

git clone https://github.com/tosin2013/mcp-memory-cache-server.git cd mcp-memory-cache-server
  1. 安装依赖项:

npm install
  1. 构建项目:

npm run build
  1. 添加到您的 MCP 客户端设置:

{ "mcpServers": { "memory-cache": { "command": "node", "args": ["/path/to/ib-mcp-cache-server/build/index.js"] } } }
  1. 当您使用 MCP 客户端时,服务器将自动启动

验证其有效性

当服务器正常运行时,您将看到:

  1. 终端中显示一条消息:“内存缓存 MCP 服务器在 stdio 上运行”

  2. 提高多次访问相同数据时的性能

  3. 您无需采取任何行动 - 缓存将自动进行

您可以通过以下方式验证服务器是否正在运行:

  1. 打开您的 MCP 客户端

  2. 在启动服务器的终端中查找任何错误消息

  3. 执行可从缓存中受益的操作(例如多次读取同一个文件)

配置

可以通过config.json或环境变量来配置服务器:

{ "maxEntries": 1000, // Maximum number of items in cache "maxMemory": 104857600, // Maximum memory usage in bytes (100MB) "defaultTTL": 3600, // Default time-to-live in seconds (1 hour) "checkInterval": 60000, // Cleanup interval in milliseconds (1 minute) "statsInterval": 30000 // Stats update interval in milliseconds (30 seconds) }

配置设置说明

  1. maxEntries (默认值:1000)

    • 缓存中可存储的最大项目数

    • 防止缓存无限增长

    • 当超出时,最旧的未使用项目将首先被删除

  2. 最大内存(默认值:100MB)

    • 最大内存使用量(以字节为单位)

    • 防止过度内存消耗

    • 当超过时,最近最少使用的项目将被删除

  3. defaultTTL (默认值:1小时)

    • 默认情况下,项目在缓存中保留多长时间

    • 此时间后,物品将自动删除

    • 防止陈旧数据消耗内存

  4. checkInterval (默认值:1分钟)

    • 服务器检查过期项目的频率

    • 较低的值可以使内存使用情况更准确

    • 较高的值可降低 CPU 使用率

  5. statsInterval (默认值:30 秒)

    • 缓存统计信息的更新频率

    • 影响命中率/未命中率的准确性

    • 帮助监控缓存有效性

如何减少代币消耗

内存缓存服务器通过自动存储原本需要在你和语言模型之间重复发送的数据来减少令牌消耗。你无需执行任何特殊操作 - 当你通过 MCP 客户端与任何语言模型交互时,缓存都会自动进行。

以下是一些缓存的示例:

1. 文件内容缓存

多次读取文件时:

  • 第一次:读取并缓存完整文件内容

  • 后续时间:从缓存中检索内容,而不是重新读取文件

  • 结果:重复文件操作使用的令牌更少

2.计算结果

进行计算或分析时:

  • 第一次:进行完整计算并缓存结果

  • 后续:如果输入相同,则从缓存中检索结果

  • 结果:用于重复计算的令牌更少

3. 经常访问的数据

当多次需要相同的数据时:

  • 第一次:数据被处理和缓存

  • 后续时间:从缓存中检索数据,直到 TTL 到期

  • 结果:使用更少的令牌来访问相同的信息

自动缓存管理

服务器通过以下方式自动管理缓存过程:

  • 首次遇到时存储数据

  • 可用时提供缓存数据

  • 根据设置删除旧的/未使用的数据

  • 通过统计数据追踪效果

优化技巧

1.设置适当的TTL

  • 对于频繁变化的数据,使用更短的

  • 静态内容更长

2.调整内存限制

  • 缓存越多,则越高(节省更多令牌)

  • 如果担心内存使用情况,则降低

3. 监控缓存统计信息

  • 高命中率=良好的代币节省

  • 低命中率=调整TTL或限制

环境变量配置

您可以使用 MCP 设置中的环境变量覆盖 config.json 设置:

{ "mcpServers": { "memory-cache": { "command": "node", "args": ["/path/to/build/index.js"], "env": { "MAX_ENTRIES": "5000", "MAX_MEMORY": "209715200", // 200MB "DEFAULT_TTL": "7200", // 2 hours "CHECK_INTERVAL": "120000", // 2 minutes "STATS_INTERVAL": "60000" // 1 minute } } } }

您还可以指定自定义配置文件位置:

{ "env": { "CONFIG_PATH": "/path/to/your/config.json" } }

服务器将:

  1. 在其目录中查找 config.json

  2. 应用任何环境变量覆盖

  3. 如果未指定,则使用默认值

在实践中测试缓存

要查看缓存的实际效果,请尝试以下场景:

  1. 文件阅读测试

    • 读取并分析大文件

    • 再次询问有关该文件的相同问题

    • 由于文件内容被缓存,第二次响应应该更快

  2. 数据分析测试

    • 对一些数据进行分析

    • 再次请求相同的分析

    • 第二次分析应该使用缓存的结果

  3. 项目导航测试

    • 探索项目的结构

    • 再次查询相同的文件/目录

    • 目录列表和文件内容将从缓存中提供

当您注意到以下情况时,缓存正在工作:

  • 重复操作响应更快

  • 对于未改变的内容,给出一致的答案

  • 无需重新读取未更改的文件

Deploy Server
A
security – no known vulnerabilities
-
license - not tested
A
quality - confirmed to work

Related MCP Servers

  • -
    security
    A
    license
    -
    quality
    MCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.
    Last updated -
    6
    4
    MIT License
  • A
    security
    F
    license
    A
    quality
    A Model Context Protocol server that reduces token consumption by efficiently caching data between language model interactions, automatically storing and retrieving information to minimize redundant token usage.
    Last updated -
    4
    17
  • A
    security
    A
    license
    A
    quality
    A Model Context Protocol (MCP) server designed to easily dump your codebase context into Large Language Models (LLMs).
    Last updated -
    366
    1
    54
    3
    Apache 2.0
  • -
    security
    A
    license
    -
    quality
    A high-performance Model Context Protocol (MCP) server designed for large language models, enabling real-time communication between AI models and applications with support for session management and intelligent tool registration.
    Last updated -
    2
    MIT License

View all related MCP servers

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/tosin2013/mcp-memory-cache-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server