Skip to content
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

Add MCP #727

Merged
merged 9 commits into from
Dec 5, 2024
Merged

Add MCP #727

merged 9 commits into from
Dec 5, 2024

Conversation

koxudaxi
Copy link
Collaborator

@koxudaxi koxudaxi commented Dec 3, 2024

Progress on: #725

examples

"""Example of MCP server for book recommendations."""

import asyncio
from pathlib import Path

from mirascope.mcp import MCPServer

# Create a server for book recommendations
app = MCPServer("book-recommend")


@app.tool()
def get_book(genre: str) -> str:
    """Get a recommendation for a specific book genre.

    Args:
        genre: Genre of book (fantasy, mystery, sci-fi, etc.)
    """
    book_recommendations = {
        "fantasy": "The Name of the Wind by Patrick Rothfuss",
        "mystery": "The Silent Patient by Alex Michaelides",
        "sci-fi": "Project Hail Mary by Andy Weir",
        "romance": "The Love Hypothesis by Ali Hazelwood",
        "historical": "The Seven Husbands of Evelyn Hugo by Taylor Jenkins Reid"
    }
    return book_recommendations.get(genre, "Please specify a valid genre")


@app.resource(
    uri="file://books.txt",
    name="Books Database",
    mime_type="text/plain",
    description="Curated database of book recommendations by genre"
)
async def read_books_database():
    """Read the books database file."""
    data = Path(__file__).parent / "books.txt"
    with data.open() as f:
        return f.read()


@app.prompt()
def recommend_book(genre: str) -> str:
    """Get book recommendations by genre.

    Args:
        genre: Genre of book to recommend (fantasy, mystery, sci-fi, etc.)
    """
    return f"Recommend a {genre} book"


async def main():
    """Run the book recommendation server."""
    await app.run()


if __name__ == "__main__":
    asyncio.run(main())
image image

@koxudaxi koxudaxi requested a review from willbakst as a code owner December 3, 2024 15:02
@koxudaxi koxudaxi marked this pull request as draft December 3, 2024 15:02
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b28358b) to head (272a9b8).
Report is 10 commits behind head on release/v1.12.

Additional details and impacted files
@@               Coverage Diff                @@
##           release/v1.12      #727    +/-   ##
================================================
  Coverage         100.00%   100.00%            
================================================
  Files                399       403     +4     
  Lines              13394     14192   +798     
================================================
+ Hits               13394     14192   +798     
Flag Coverage Δ
tests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mirascope/mcp/server.py Outdated Show resolved Hide resolved
mirascope/mcp/server.py Outdated Show resolved Hide resolved
mirascope/mcp/server.py Outdated Show resolved Hide resolved
@koxudaxi koxudaxi marked this pull request as ready for review December 4, 2024 09:01
@koxudaxi koxudaxi requested a review from willbakst December 4, 2024 14:48
mirascope/mcp/server.py Outdated Show resolved Hide resolved
mirascope/mcp/server.py Outdated Show resolved Hide resolved
@koxudaxi koxudaxi requested a review from willbakst December 5, 2024 01:35
willbakst
willbakst previously approved these changes Dec 5, 2024
@willbakst willbakst changed the base branch from main to release/v1.12 December 5, 2024 16:02
@willbakst willbakst dismissed their stale review December 5, 2024 16:02

The base branch was changed.

@willbakst willbakst merged commit be1a85b into release/v1.12 Dec 5, 2024
7 checks passed
@willbakst willbakst deleted the add-mcp branch December 5, 2024 16:02
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