macOS 사용자 가이드
1. 가상환경 설정
macOS에서 MCP를 사용하기 위해서는 가상환경을 설정해야 합니다. 가상환경을 설정하지 않을 경우 연결하는데 아래와 같은 애러가 발생할 수 있습니다.
Traceback (most recent call last):
File "/Users/실제유저이름/Desktop/test/tutorial_1.py", line 1, in <module>
from mcp.server.fastmcp import FastMCP
Traceback (most recent call last):
File "/Users/실제유저이름/Desktop/test/tutorial_1.py", line 1, in <module>
from mcp.server.fastmcp import FastMCP
아래의 명령어를 터미널에 입력하여 가상환경을 생성하고 활성화합니다.
python3 -m venv venv
source venv/bin/activate
pip install mcp
python3 -m venv venv
source venv/bin/activate
pip install mcp
2. 경로명과 명령어
mac의 경로명은 윈도우와 다르게 /Users/사용자이름/
으로 시작하며 구분자는 /
입니다. 또한 명령어도 python
이 아니라 python3
일 수 있습니다. 따라서 tutorial_2와 같은 경우 아래와 같이 수정되어야 합니다.
# tutorial_2.py
from mcp.server.fastmcp import FastMCP
import sys
# MCP 서버 생성
mcp = FastMCP(name="tutorial_2", host="127.0.0.1", port=5001, timeout=30)
# 폴더 생성 도구
@mcp.tool()
def create_folder(folder_name: str) -> str:
"""
현재 파일이 있눈 곳에 폴더를 생성합니다.
"""
import os
# mac 코드
# 현재 폴더 가져오기
current_folder = os.getcwd()
# 현재 폴더에 folder_name 폴더 이름 결합
folder_path = os.path.join(current_folder, folder_name)
# windows 코드
# folder_path = os.path.join("c:/test", folder_name)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
return f"폴더 '{folder_name}' 가 생성되었습니다."
else:
return f"폴더 '{folder_name}' 는 이미 존재합니다."
# 서버 실행
mcp.run()
# tutorial_2.py
from mcp.server.fastmcp import FastMCP
import sys
# MCP 서버 생성
mcp = FastMCP(name="tutorial_2", host="127.0.0.1", port=5001, timeout=30)
# 폴더 생성 도구
@mcp.tool()
def create_folder(folder_name: str) -> str:
"""
현재 파일이 있눈 곳에 폴더를 생성합니다.
"""
import os
# mac 코드
# 현재 폴더 가져오기
current_folder = os.getcwd()
# 현재 폴더에 folder_name 폴더 이름 결합
folder_path = os.path.join(current_folder, folder_name)
# windows 코드
# folder_path = os.path.join("c:/test", folder_name)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
return f"폴더 '{folder_name}' 가 생성되었습니다."
else:
return f"폴더 '{folder_name}' 는 이미 존재합니다."
# 서버 실행
mcp.run()
3. 설정 파일
windows와 비교를 위해 함게 올려드립니다. 이런 식으로 명령어를 수정하지 않으면 모듈을 찾을 수 없다는 애러가 발생할 수 있습니다.
# window
{
"mcpServers": {
"math": {
"command": "python",
"args": [
"C:\\test\\quickstart.py"
]
},
"tutorial_1": {
"command": "python",
"args": [
"C:\\test\\tutorial_1.py"
]
},
"tutorial_2": {
"command": "python",
"args": [
"C:\\test\\tutorial_2.py"
]
}
}
}
# mac
{
"mcpServers": {
"tutorial_1": {
"command": "bash",
"args": [
"-c",
"cd /Users/실제유저이름/Desktop/test && source venv/bin/activate && python3 /Users/실제유저이름/Desktop/test/tutorial_1.py"
]
},
"tutorial_2": {
"command": "bash",
"args": [
"-c",
"cd /Users/실제유저이름/Desktop/test && source venv/bin/activate && python3 /Users/실제유저이름/Desktop/test/tutorial_2.py"
]
}
}
}
# window
{
"mcpServers": {
"math": {
"command": "python",
"args": [
"C:\\test\\quickstart.py"
]
},
"tutorial_1": {
"command": "python",
"args": [
"C:\\test\\tutorial_1.py"
]
},
"tutorial_2": {
"command": "python",
"args": [
"C:\\test\\tutorial_2.py"
]
}
}
}
# mac
{
"mcpServers": {
"tutorial_1": {
"command": "bash",
"args": [
"-c",
"cd /Users/실제유저이름/Desktop/test && source venv/bin/activate && python3 /Users/실제유저이름/Desktop/test/tutorial_1.py"
]
},
"tutorial_2": {
"command": "bash",
"args": [
"-c",
"cd /Users/실제유저이름/Desktop/test && source venv/bin/activate && python3 /Users/실제유저이름/Desktop/test/tutorial_2.py"
]
}
}
}