티스토리 뷰
MCP 리모트 서버를 생성 후 실행시키면 기본적으로 8000번 포트를 사용합니다.
상황에 따라서 포트번호를 변경하거나 host 주소를 변경해야 할 일이 있는데요. 막상 Document와는 달라서 삽질을 좀 했습니다.

기본적으로 MCP서버는 파이썬 패키지의 FastMCP를 이용해서 간단하게 생성이 가능합니다.
페이지의 문서를 찾아보면 다음과 같이 host와 port를 지정해서 실행을 시키던데요.
https://gofastmcp.com/deployment/running-server
Running Your Server - FastMCP
Learn how to run your FastMCP server locally for development and testing
gofastmcp.com
mcp.run() 의 인자로 Transport Protocol, host, port 를 지정할 수 있다고 되어 있는데, 막상 적용하면 에러가 납니다.
from fastmcp import FastMCP
mcp = FastMCP("MyServer")
@mcp.tool
def hello(name: str) -> str:
return f"Hello, {name}!"
if __name__ == "__main__":
# Start an HTTP server on port 8000
mcp.run(transport="http", host="127.0.0.1", port=8000)
host는 localhost가 아닌 0.0.0.0으로 변경하고 포트번호도 8000이 아닌 2424번 포트를 써보려고 넣어봤는데 잘 안되더라구요.
이렇게 실행하면 unexpected keyword argument 'host' 라며 에러가 발생합니다.
그럼 어떻게 하느냐...?
삽질하다가 찾은 방법 입니다.
from mcp.server.fastmcp import FastMCP
import aiohttp
mcp = FastMCP("MCP Server", host="0.0.0.0", port=2424)
... (중략)
if __name__ == "__main__":
mcp.run(transport="http")
FastMCP 생성할때 넣어주면 되는거였습니다.
제가 만들려던 MCP서버는 clickhouse db 쿼리를 지원하는 서버 였는데요.
이런식으로 만들어서 연결해 봤습니다. 참고로 clickhouse server는 docker로 같은 호스트에서 실행중이고 localhost:8123 포트로 접근이 가능하도록 해놓은 상태입니다.
from mcp.server.fastmcp import FastMCP
import clickhouse_connect
import uvicorn
# 1. FastMCP 초기화
mcp = FastMCP("ClickHouse-Server", host="0.0.0.0", port=2424)
# 2. ClickHouse 연결 툴들
def get_client():
return clickhouse_connect.get_client(
host='127.0.0.1',
port=8123,
username='default',
password=''
)
@mcp.tool()
def query(sql: str) -> str:
"""ClickHouse SQL을 실행합니다."""
try:
client = get_client()
result = client.query(sql)
return str(result.result_rows)
except Exception as e:
return f"Error: {e}"
if __name__ == "__main__":
mcp.run(transport='http')
- Total
- Today
- Yesterday
- 앞유리돌빵
- 통관번호
- 가죽여권케이스
- 워치어베인 2nd edition
- chromecast2
- 커플여권케이스
- LG워치 어베인
- LGG6
- 개인통관번호
- LG워치
- 커플여권지갑
- 워치어베인
- AR Stickers
- 워치어베인 2nd 에디션
- 글로벌자동차유리
- 오드컨테이너
- AR스티커
- 무료복원
- 자동차유리스톤칩
- 가죽여권지갑
- 통관부호
- 미성년자녀증여세
- 증여세셀프신고
- LGPay
- 통관번호변경
- 크롬캐스트2
- LG페이
- 유리스톤칩
- 통관번호재발급
- 에어팟안드로이드
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |