lchenudc/AIagent_hlnews_first
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
- Use virtual environments (recommended):
python -m venv .venv
source .venv/bin/activate
- Install MCP and LangChain (if needed):
pip install mcp
pip install langchain langchain-mcp-adapters langgraph
- Install dependencies (if using a
requirements.txt
):
pip install -r requirements.txt
- 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
Task | With Python | With UV |
---|---|---|
Create project | mkdir my_project | uv init my_project |
Add dependencies | pip install ... | uv add ... |
Run server | python server.py | uv run mcp dev server.py |
Run client | python client.py | uv run mcp or uv exec |
Virtual environment | python -m venv .venv | handled 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.