Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions python/samples/concepts/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ pip install semantic-kernel[mcp]
cd python/samples/concepts/mcp
python <name>.py
```
### BGPT sample

The `agent_with_bgpt_mcp_plugin.py` sample demonstrates how to connect
Semantic Kernel to the BGPT MCP server using `MCPStreamableHttpPlugin`
for evidence-based scientific literature retrieval.

Before running the sample, configure the required Azure OpenAI
environment variables as described in the sample file.

Comment on lines +48 to +50
Run the sample:

```bash
cd python/samples/concepts/mcp
python agent_with_bgpt_mcp_plugin.py
```
75 changes: 75 additions & 0 deletions python/samples/concepts/mcp/agent_with_bgpt_mcp_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright (c) Microsoft. All rights reserved.

import asyncio

from azure.identity import AzureCliCredential

from semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion
from semantic_kernel.connectors.mcp import MCPStreamableHttpPlugin

"""
This sample demonstrates how to connect a ChatCompletionAgent
to the BGPT MCP Server using the MCPStreamableHttpPlugin.

BGPT provides evidence-based retrieval over scientific literature
through a remote MCP server.

It uses the Azure OpenAI service to create an agent. Make sure the
following environment variables are configured:

- AZURE_OPENAI_CHAT_DEPLOYMENT_NAME
- Optionally: AZURE_OPENAI_API_KEY

If no API key is configured, AzureCliCredential can also be used.
"""
Comment on lines +18 to +25


# Example biomedical question
USER_INPUTS = [
"Find recent papers about CRISPR gene editing in wheat.",
]


async def main() -> None:
# Create the BGPT MCP plugin
async with MCPStreamableHttpPlugin(
name="BGPT",
description="BGPT Scientific Literature Search",
url="https://bgpt.pro/mcp/stream",
) as bgpt_plugin:

# Create the agent
agent = ChatCompletionAgent(
service=AzureChatCompletion(
credential=AzureCliCredential(),
),
name="BGPTAgent",
instructions=(
"You are a biomedical research assistant. "
"Use the BGPT MCP server to retrieve and summarize "
"scientific evidence."
),
plugins=[bgpt_plugin],
)

for user_input in USER_INPUTS:
thread: ChatHistoryAgentThread | None = None

print(f"# User: {user_input}")

response = await agent.get_response(
messages=user_input,
thread=thread,
)

print(f"# {response.name}: {response}")

thread = response.thread

if thread:
await thread.delete()


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