Token导航 LogoToken导航TokenDH.com
dynamiccontextloading logo
AI代理stdio官方级别未说明来源级核验

dynamiccontextloading

MCP Server

DynamicContextLoading是一种用于LLMs和MCP的按需工具激活技术,通过仅在需要时加载工具来防止上下文膨胀。

工具数

0

提示词数

0

GitHub Stars

3

资源数

0
Python上下文管理AI代理

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

CefBoud

提供方

CefBoud

最后核验

2026/5/17 20:19

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uv run dcl_mcp.py

详细介绍

针对大型语言模型(LLMs)和多上下文处理(MCP)的动态上下文加载

概述

动态上下文加载(DynamicContextLoading)是一种在大型语言模型(LLMs)和机器控制平台(MCP)中按需激活工具的技术,通过仅在需要时加载工具,避免了上下文臃肿的问题。

背景

在开发过程中 蒙科德作为一个简单的编码代理,我注意到上下文中充斥着工具定义,其中许多工具很少使用。这种低效启发了(我/我们) loader 一个工具,它提供了工具的简要概述,并且仅在需要时动态加载完整详细信息。

这种方法适用于MCP(多上下文处理),因为在MCP中,多个服务器可能会占用大量的上下文空间。可以实现多级加载,类似于缓存层次结构:服务器描述、工具摘要和完整定义。

问题

大型语言模型(LLMs)具有有限的上下文窗口。在每次交互中都包含所有工具会导致更高的成本、更慢的响应速度、准确性降低以及令牌限制错误。这种方法通过动态激活工具,以实现简洁的上下文处理。

示例:函数调用

看见 dcl_function_calling.py 用于实施。用途 litellm (通过设置 .env 基于 .env.example)。

示例交互:

User: Calculate 15 * 7 and get weather in New York.

Activated tools: calculator, get_weather

15 * 7 = 105
Weather in New York: cloudy, 8°C.

示例:MCP(多协议控制器)集成

通过多级加载方式(从1开始,仅在需要时继续加载2和3)与MCP服务器(例如,通过stdio连接GitHub)集成:

  1. 服务器描述初始加载高级服务器信息。
  2. 工具概述按需为特定服务器加载简报。
  3. 完整工具集仅激活完成任务所需的工具。

这种渐进式的加载方式保持了上下文的高效性。

uv run dcl_mcp.py (需要 .env 和;与;带有 GITHUB_PERSONAL_ACCESS_TOKEN (用于完整演示)。详见下文扩展示例。

Click to expand condensed example run (showing two-level loading sequence)

# Run the script (assumes .env with GITHUB_PERSONAL_ACCESS_TOKEN set)
uv run dcl_mcp.py

# Output shows MCP servers initializing and listing tools
load_mcp_tools github ['add_comment_to_pending_review', 'add_issue_comment', ...]
load_mcp_tools figma ['get_figma_data', 'download_figma_images']

# Initial loader description: Only server-level info loaded
generated loader tool description: Dynamic Tool Loader for managing MCP tools...
'github' MCP: The GitHub MCP server provides tools for comprehensive GitHub management...
'figma' MCP: This MCP server enables fetching detailed Figma file data...

# User query triggers loader activation
User: Provide a list of 5 of my public GitHub repositories

# LLM uses loader to load GitHub tool summaries (Level 2)
tool call: {"action":"load_tool_summaries","servers":["github"]}
Loader result: Loaded tool summaries for servers: github.

# Now context includes tool briefs for GitHub
Tools summaries loaded:
- get_me: Retrieves details of the authenticated GitHub user.
- search_repositories: Searches for repositories by name, topics, or metadata.
[... other tools ...]

# LLM activates specific tools (Level 3)
tool call: {"action":"load_tools","tools":["get_me","search_repositories"],"server":"github"}
Loader result: Activated tools from github: get_me, search_repositories.

# Tools now active and callable
active tools: loader, get_me, search_repositories

# LLM calls get_me to get user info
tool call: {} (for get_me)
get_me result: {"login":"CefBoud", ...}

# Then calls search_repositories with query
tool call: {"query":"user:CefBoud","sort":"updated"} (for search_repositories)
search_repositories result: List of 5 public repos (e.g., MonCoder, cefboud.github.io, etc.)

# Final response from LLM
Assistant: Here is a list of 5 of your public GitHub repositories...

目录标签

目录标签

Python上下文管理AI代理动态加载本地部署LLM优化MCP集成工具激活

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

session

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiosession部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP