AIagent_hlnews_first

lchenudc/AIagent_hlnews_first

3.2

If you are the rightful owner of AIagent_hlnews_first and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Model Context Protocol (MCP) is a framework designed to facilitate secure and efficient interactions between AI servers and LLM applications, akin to a web API but tailored for LLMs.

README.md

๐Ÿง  What is MCP?

From "MCP Python SDK":

The Model Context Protocol (MCP) lets you build AI servers that securely expose data and functionality to LLM applications โ€” similar to a web API, but specifically designed for LLM interactions.

MCP servers can:

  • ๐Ÿ“„ Expose data through Resources (like GET endpoints).
  • ๐Ÿ› ๏ธ Provide functionality through Tools (like POST endpoints).
  • โœ๏ธ Define reusable prompt templates through Prompts.
  • ๐Ÿ”Œ And more!

โš™๏ธ Method 1: Basic Python (No uv)

๐Ÿงช Step-by-Step

Step 1: Create your project folder

mkdir AIagent_hlnews_first
cd AIagent_hlnews_first

Copy or create your files here. For example:

  • client3.py
  • server_headlinenews.py

Step 2: Launch the server

python3 server_headlinenews.py  

(Note: Depending on your computerโ€™s setup, the Python command might be python instead of python3. Use whichever command runs Python 3.x on your system.)

โœ… If successful, youโ€™ll see something like:
๐Ÿš€ HeadlineNews MCP Server running via stdioโ€ฆ

You can also try:

mcp dev server_headlinenews.py

Step 3: Run the client

python3 client3.py

โœ… This will start the client, which may also auto-launch the server depending on how itโ€™s coded.

Alternate:

mcp dev client

Step 3-1: Run the client

python3 client5_loop.py

โœ… This will start the client with a menu selection through a while loop. It may also auto-launch the server depending on how itโ€™s coded.

๐Ÿ›  Notes

  1. Use virtual environments (recommended):
python -m venv .venv
source .venv/bin/activate
  1. Install MCP and LangChain (if needed):
pip install mcp
pip install langchain langchain-mcp-adapters langgraph
  1. Install dependencies (if using a requirements.txt):
pip install -r requirements.txt
  1. API Keys

If you need access to external APIs like NewsAPI or OpenAI:

Create a .env file:

NEWSAPI_KEY=your_api_key
OPENAI_API_KEY=your_openai_key

Or set the key directly:

NEWSAPI_KEY = "your_key_here"

๐Ÿš€ Method 2: Using uv (Optional but Powerful)

uv is a fast Python package and project manager written in Rust.


Step 1: Create your project

uv init AIagent_hlnews_simple
cd AIagent_hlnews_simple

Then copy or create your files: client3.py, server_headlinenews.py


Step 2: Add MCP dependency

uv add "mcp[cli]"

(Or if you're using pip: pip install "mcp[cli]")


Step 3: Run your MCP app

uv run mcp

Or just run:

uv venv exec python client3.py

Step 4: Run dev server

uv run mcp dev server_headlinenews.py

๐Ÿง  This will start your MCP server in dev mode. MCP may also prompt to install a browser-based inspector.


Step 5: Run your client

uv venv exec python client3.py

โœ… Summary

TaskWith PythonWith UV
Create projectmkdir my_projectuv init my_project
Add dependenciespip install ...uv add ...
Run serverpython server.pyuv run mcp dev server.py
Run clientpython client.pyuv run mcp or uv exec
Virtual environmentpython -m venv .venvhandled by uv

๐Ÿ“œ License

MIT License โ€“ Feel free to adapt or reuse.

Acknowledgment

This small code sample project was built with support and assistance from ChatGPT.

Appendix about MIT License

Copyright (c) 2025 Thu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.