Skip to content

Conversation

@ezynda3
Copy link
Contributor

@ezynda3 ezynda3 commented Sep 2, 2025

Summary

  • Adds SDK package that allows Go applications to use MCPHost programmatically without spawning OS processes
  • Maintains identical behavior to CLI including configuration loading, environment variables, and defaults

Changes

  • Export required functions from cmd package: Made InitConfig() and LoadConfigWithEnvSubstitution() public to allow SDK to reuse CLI initialization logic
  • Create SDK package with:
    • Main MCPHost type for programmatic access
    • Configuration options for overriding defaults
    • Session management capabilities
    • Type helpers for Message and ToolCall
    • Comprehensive documentation and examples
    • Unit test coverage

Key Features

  • ✅ Simple Prompt() method for basic usage
  • PromptWithCallbacks() for monitoring tool execution in real-time
  • ✅ Session persistence (load/save/clear)
  • ✅ Full compatibility with CLI configuration system
  • ✅ Respects all environment variables
  • ✅ Resource cleanup with Close() method

Testing

  • All existing tests pass with race detection
  • New SDK tests verify initialization, options, and session management
  • Examples compile and run successfully
  • Code passes linting and formatting checks

Usage Example

package main

import (
    "context"
    "fmt"
    "github.com/mark3labs/mcphost/sdk"
)

func main() {
    ctx := context.Background()
    
    // Create MCPHost instance
    host, err := sdk.New(ctx, nil)
    if err != nil {
        panic(err)
    }
    defer host.Close()
    
    // Send prompt
    response, err := host.Prompt(ctx, "What is 2+2?")
    fmt.Println(response)
}

Documentation

  • Comprehensive README in sdk/README.md
  • Working examples in sdk/examples/
  • Full API documentation with all methods and types

- Export InitConfig and LoadConfigWithEnvSubstitution from cmd package
- Create sdk package with MCPHost type for programmatic access
- Add Options struct for configuration overrides
- Implement Prompt and PromptWithCallbacks methods
- Add session management (load, save, clear)
- Create type helpers for Message and ToolCall
- Add comprehensive SDK documentation in README
- Include basic and scripting examples
- Add unit tests for SDK functionality

The SDK reuses all existing internal packages and maintains identical
behavior to the CLI, including config loading, environment variables,
and defaults.
@ezynda3 ezynda3 merged commit f778379 into main Sep 2, 2025
1 check passed
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.

2 participants