Skip to content

Conversation

@Hoder-zyf
Copy link
Collaborator

@Hoder-zyf Hoder-zyf commented Jul 31, 2025

Description

This PR integrates a new MCP (Model Context Protocol) Context7 capability and wires it into the coder/data-science pipeline so the agent can search relevant documentation when encountering implementation errors.

Key changes

  • Introduce a new rdagent.components.mcp package with a dedicated context7 module, including client, prompts, examples, and README, enabling MCP-based doc search.
  • Add/modify pipeline hooks to surface error context and enable doc retrieval, notably in rdagent/components/coder/data_science/pipeline/eval.py and its prompts.yaml.
  • Update rdagent/app/data_science/conf.py to make Context7 usage configurable; control via the CONTEXT7_ENABLED environment variable. Also adjusts the hypothesis critique toggle default.
  • Touch related evaluator logic under rdagent/components/coder/CoSTEER/evaluators.py to align with the pipeline changes.
  • Minor housekeeping edits in .devcontainer/devcontainer.json and .gitignore.

Why it matters

  • Adds an opt-in documentation search path that improves error diagnosis and remediation during coding runs, reducing manual context switching and speeding iteration.

Configuration

  • To enable Context7 MCP at runtime, set:
    • CONTEXT7_ENABLED=1 and MCP_ENABLED=True

Motivation and Context

Agent runs often fail due to missing APIs, library nuances, or environment quirks. Integrating an MCP-driven doc search lets the system proactively fetch relevant references based on the current error, guiding the next fix step. The added config flag ensures teams can roll this out gradually and A/B the impact.

Types of changes

  • Add new feature
  • Fix bugs
  • Update documentation

Hoder-zyf and others added 8 commits July 29, 2025 14:45
…age and mcp to be discussed; the extraction logic not done yet; the config load is ugly) init commit 2
- Refine context7.py prompt
- Handle/pause on timeout
- Optimize context7 logic
- Pass content downstream when enabled
- Add PyTorch Image Models (timm) search to index.ts
@Hoder-zyf Hoder-zyf changed the title feat: integrate Context7 MCP documentation search functionality in runner feat: integrate Context7 MCP documentation search functionality in coder Aug 1, 2025
@Hoder-zyf Hoder-zyf marked this pull request as ready for review August 1, 2025 15:28
- Implement litellm integration for MCP extra configuration
- Enable flexible model calling through litellm adapter

Next steps:
- [ ] Multi-MCP registration and validation
- [ ] Eval module testing
- [ ] Code refactoring for better readability
- [ ] README documentation
@Hoder-zyf Hoder-zyf marked this pull request as draft August 28, 2025 17:42
  Replace dual-function API (query_mcp/query_mcp_auto) with single flexible
  interface supporting three modes: auto (all services), single service, and
  multi-service parallel processing.

  Key improvements:
  - Remove API complexity: one function instead of two
  - Enable true parallelism: services run concurrently, not sequentially
  - Add MultiServiceContext for efficient connection management
  - Fix LiteLLM tool calling edge cases with proper finish_reason handling
  - Update examples demonstrating new unified interface

  Performance impact: Multi-service queries now execute in parallel rather
  than trying services one by one, significantly reducing response time.

  Breaking change: query_mcp_auto() removed, use query_mcp() instead.
  - Add verbose parameter to control logging output levels
    - Default (verbose=False): Show only essential logs
    - Verbose mode (verbose=True): Show detailed debugging info
  - Enhance error detection with comprehensive pattern matching
    - Add rate limit error detection ('rate limit', 'too many
  requests')
    - Add content availability errors ('no content available')
    - Fix MCP services returning errors as successful responses
  - Refactor error handling with data-driven approach
    - Consolidate error patterns into ERROR_DEFINITIONS constant
    - Eliminate code duplication in error detection functions
    - Add priority-based error message formatting
  - Remove cost calculation logging from LiteLLM backend
  - Clean up unused imports and improve code organization
"mcpServices": {
"context7": {
"url": "http://localhost:8123/mcp",
"handler": "rdagent.components.mcp.context7.handler:Context7Handler",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mix the API Handler and the prompt customization.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two different responsibility.

  1. API Handler (1 - 1)
  2. prompt customization. ( Agent level custmization, Many-to-many )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCPAgent + MCPService( API Handler is included)

@Hoder-zyf Hoder-zyf changed the title feat: integrate Context7 MCP doc search with coder pipeline & configurable mcp toggle feat: add mcp components Sep 8, 2025
@Hoder-zyf Hoder-zyf changed the title feat: add mcp components fix: add mcp components Sep 8, 2025
@Hoder-zyf Hoder-zyf closed this Sep 8, 2025
@Hoder-zyf Hoder-zyf reopened this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants