폴더 생성
1. 파일 생성
이번에는 폴더를 생성하는 코드를 추가해보도록 하겠습니다. 같은 폴더에 tutorial_2.py
라는 파일을 만들고 아래와 같이 작성해주세요.
from mcp.server.fastmcp import FastMCP
# MCP 서버 생성
mcp = FastMCP(name="tutorial_2", host="127.0.0.1", port=5001, timeout=30)
# 폴더 생성 도구
@mcp.tool()
def create_folder(folder_name: str) -> str:
"""
c:/test/ 아래 폴더를 생성합니다.
"""
import os
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}' 는 이미 존재합니다."
# 서버 실행
if __name__ == "__main__":
mcp.run()
from mcp.server.fastmcp import FastMCP
# MCP 서버 생성
mcp = FastMCP(name="tutorial_2", host="127.0.0.1", port=5001, timeout=30)
# 폴더 생성 도구
@mcp.tool()
def create_folder(folder_name: str) -> str:
"""
c:/test/ 아래 폴더를 생성합니다.
"""
import os
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}' 는 이미 존재합니다."
# 서버 실행
if __name__ == "__main__":
mcp.run()
2. 설정파일 작성
claude_desktop_config.json 파일을 아래와 같이 수정해주세요.
{
"mcpServers": {
"tutorial_1": {
"command": "python",
"args": [
"C:\\test\\tutorial_1.py"
]
},
"tutorial_2": {
"command": "python",
"args": [
"C:\\test\\tutorial_2.py"
]
}
}
}
{
"mcpServers": {
"tutorial_1": {
"command": "python",
"args": [
"C:\\test\\tutorial_1.py"
]
},
"tutorial_2": {
"command": "python",
"args": [
"C:\\test\\tutorial_2.py"
]
}
}
}
3. 클로드 재시작
클로드를 재시작하면 create_folder
라는 함수를 사용할 수 있게 됩니다. 프롬프트 입력 창에 망치 버튼을 클릭하면 아래와 같이 사용한 도구를 보실 수 있습니다.

4. 프롬프트
아래와 같은 프롬프트로 실행할 수 있습니다. 그러면 자동으로 create_folder라는 함수를 호출하여 c:/test/hello
라는 폴더를 생성합니다.
hello라는 폴더를 생성해줘.
hello라는 폴더를 생성해줘.