Skip to content

feat: mcp support, openai update, refactor #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
May 23, 2025
Merged

feat: mcp support, openai update, refactor #486

merged 49 commits into from
May 23, 2025

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Apr 22, 2025

This ended up being a way bigger change than I thought it would, and I think we should probably refactor further.

So far, this is what I've done:

  • refactor: use anthropic sdk #487
  • configuration to setup MCP servers
  • flags to disable all/specific MCP servers
  • updated openAI library
  • updated anthropic library
  • refactor to use ollama library instead of our own code
  • refactor improving code organization, new streaming client interface
  • create a proto package with generic types to use with all clients
  • improved how topP, topK, and others are handled
  • port relevant parts of DRAFT - initial stab at MCP support #460
  • MCP support for openai
  • MCP support for anthropic
  • MCP support for ollama
  • tool calls are not properly stored in the cache in anthropic
  • continuing conversations doesn't work
  • tool calls not handled in cohere (future)
  • tool calls not handled in google (future)
  • use google sdk (future)

Since we support a myriad of providers, for now I think we can add MCP to only anthropic and openai to get a feel on how it'll hold up.

It looks like this:

CleanShot 2025-05-21 at 17 17 41@2x

closes #460
closes #397

@caarlos0 caarlos0 self-assigned this Apr 22, 2025
@caarlos0 caarlos0 requested review from Copilot, meowgorithm, aymanbagabas and andreynering and removed request for Copilot April 25, 2025 19:40
@caarlos0 caarlos0 added the enhancement New feature or request label Apr 25, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aims to support multiple MCP providers while refactoring and standardizing client interactions for OpenAI, Anthropic, Cohere, Ollama, and Google streams. The key changes include:

  • Replacing the legacy openai package with the new "github.com/openai/openai-go" package and updating client configuration types.
  • Refactoring stream handling methods and message conversion logic across multiple modules.
  • Adding support and CLI flags for MCP functionality (listing MCP servers and tools).

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
stream.go Updated client configuration and message role remapping for OpenAI streams.
openai.go Introduced new OpenAI client config and stream logic with minor error formatting issues.
ollama.go Adjusted stream response types and error handling to match new API types.
mods.go Updated config usage, error handling, and stream command logic.
mcp.go Added MCP support functions and tool-calling logic.
main.go Introduced new CLI flags for MCP features and updated flag registration.
google.go, format.go, config.go, cohere.go, cache.go, anthropic.go Updated type conversions, error handling, and message encoding/decoding.
Files not reviewed (1)
  • go.mod: Language not supported

@caarlos0 caarlos0 changed the title wip: mcp support and refactoring feat: mcp support, openai update, refactor Apr 25, 2025
@caarlos0 caarlos0 requested a review from Copilot May 21, 2025 20:18
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for MCP servers while refactoring and updating various API clients (Google, OpenAI, Anthropic, Cohere) along with improvements in caching and configuration. Key changes include:

  • Adding MCP server configuration options and command-line flags.
  • Refactoring client implementations and their types (e.g., renaming token structs in Copilot).
  • Migrating to generic cache implementations and updating dependency versions.

Reviewed Changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/google/google.go Added Google client streaming support with minor error message inconsistency.
internal/google/format.go Refactored conversion from proto messages to Google-specific content.
internal/copilot/copilot.go Updated Copilot authentication handling and renamed types for clarity.
internal/cohere/* Integrated and refactored support for the Cohere API client streaming.
internal/cache/* Introduced generic expiring and conversation cache implementations.
internal/anthropic/* Enhanced Anthropic streaming client and message conversion functions.
config.go & config_template.yml Added and documented MCP server options in configuration.
go.mod & README.md Updated dependencies and usage documentation to reflect new MCP support.
Comments suppressed due to low confidence (1)

internal/copilot/copilot.go:46

  • [nitpick] The field name 'cache' is ambiguous as it appears to store the cache directory. Renaming it to 'cacheDir' would better indicate its purpose.
cache       string

@caarlos0
Copy link
Member Author

BTW, some more MCP servers to use in testing:

mcp-servers:
  github:
    command: docker
    args:
    - run
    - "-i"
    - "--rm"
    - "-e"
    - GITHUB_PERSONAL_ACCESS_TOKEN
    - "ghcr.io/github/github-mcp-server"
  puppeteer:
    command: docker
    args:
    - run
    - "-i"
    - "--rm"
    - "--init"
    - "-e"
    - DOCKER_CONTAINER=true
    - mcp/puppeteer
  sequentialthinking:
    command: docker
    args:
      - run
      - --rm
      - -i
      - mcp/sequentialthinking
  time:
    command: docker
    args:
    - run
    - -i
    - --rm
    - mcp/time
    - --local-timezone=America/Sao_Paulo
  memory:
    command: docker
    args:
    - run
    - -i
    - --rm
    - mcp/memory
  fetch:
    command: docker
    args:
    - run
    - -i
    - --rm
    - mcp/fetch

@caarlos0 caarlos0 requested a review from Copilot May 23, 2025 17:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for MCP servers for selected providers (Anthropic and OpenAI), updates the OpenAI and Anthropics libraries, and refactors client implementations along with better code organization and a new streaming client interface. Key changes include the addition of MCP server configuration in the config files, major refactoring and renaming in the copilot and client packages, and removal of legacy code files.

Reviewed Changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/google/google.go Refactored Google API client implementation with an incorrect API reference in comments.
internal/copilot/copilot.go Renamed and refactored Copilot client components to improve clarity.
internal/cohere/(format.go, cohere.go) Updated Cohere client implementation and message conversion logic.
internal/cache/(expiring.go, convo.go, cache.go) Updated caching mechanisms and associated tests.
internal/anthropic/(format.go, anthropic.go) Refactored Anthropic client code and added MCP tool integration.
config_template.yml, config.go Extended configuration support for MCP servers and renamed config fields.
go.mod, README.md Updated dependencies and documentation to reflect new features.

@caarlos0 caarlos0 merged commit c48ad6b into main May 23, 2025
16 checks passed
@caarlos0 caarlos0 deleted the mcp-anthropic branch May 23, 2025 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add MCP Support
3 participants